mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-02-08 23:20:12 +00:00
fixed potential crashes when setting fontsize to a too large value
This commit is contained in:
parent
015f6227fa
commit
317e2637ec
@ -118,7 +118,15 @@ EX int getnext(const char* s, int& i) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if CAP_SDLTTF
|
#if CAP_SDLTTF
|
||||||
TTF_Font *font[256];
|
const int max_font_size = 288;
|
||||||
|
TTF_Font* font[max_font_size+1];
|
||||||
|
|
||||||
|
void fix_font_size(int& size) {
|
||||||
|
if(size < 1) size = 1;
|
||||||
|
if(size > max_font_size) size = max_font_size;
|
||||||
|
if(size > 72) size &=~ 3;
|
||||||
|
if(size > 144) size &=~ 7;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CAP_SDL
|
#if CAP_SDL
|
||||||
@ -142,6 +150,7 @@ EX color_t& qpixel(SDL_Surface *surf, int x, int y) {
|
|||||||
EX string fontpath = ISWEB ? "sans-serif" : HYPERPATH "DejaVuSans-Bold.ttf";
|
EX string fontpath = ISWEB ? "sans-serif" : HYPERPATH "DejaVuSans-Bold.ttf";
|
||||||
|
|
||||||
void loadfont(int siz) {
|
void loadfont(int siz) {
|
||||||
|
fix_font_size(siz);
|
||||||
if(!font[siz]) {
|
if(!font[siz]) {
|
||||||
font[siz] = TTF_OpenFont(fontpath.c_str(), siz);
|
font[siz] = TTF_OpenFont(fontpath.c_str(), siz);
|
||||||
// Destination set by ./configure (in the GitHub repository)
|
// Destination set by ./configure (in the GitHub repository)
|
||||||
@ -160,6 +169,7 @@ void loadfont(int siz) {
|
|||||||
|
|
||||||
#if !ISFAKEMOBILE && !ISANDROID & !ISIOS
|
#if !ISFAKEMOBILE && !ISANDROID & !ISIOS
|
||||||
int textwidth(int siz, const string &str) {
|
int textwidth(int siz, const string &str) {
|
||||||
|
fix_font_size(siz);
|
||||||
if(isize(str) == 0) return 0;
|
if(isize(str) == 0) return 0;
|
||||||
|
|
||||||
#if CAP_SDLTTF
|
#if CAP_SDLTTF
|
||||||
@ -357,7 +367,8 @@ struct glfont_t {
|
|||||||
float tx0[CHARS], tx1[CHARS], ty0[CHARS], ty1[CHARS];
|
float tx0[CHARS], tx1[CHARS], ty0[CHARS], ty1[CHARS];
|
||||||
};
|
};
|
||||||
|
|
||||||
glfont_t *glfont[256];
|
const int max_glfont_size = 72;
|
||||||
|
glfont_t *glfont[max_glfont_size+1];
|
||||||
|
|
||||||
typedef Uint16 texturepixel;
|
typedef Uint16 texturepixel;
|
||||||
|
|
||||||
@ -441,12 +452,14 @@ void init_glfont(int size) {
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
SDL_Surface *txt;
|
SDL_Surface *txt;
|
||||||
|
int siz = size;
|
||||||
|
fix_font_size(siz);
|
||||||
if(ch < 128) {
|
if(ch < 128) {
|
||||||
str[0] = ch;
|
str[0] = ch;
|
||||||
txt = TTF_RenderText_Blended(font[size], str, white);
|
txt = TTF_RenderText_Blended(font[siz], str, white);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
txt = TTF_RenderUTF8_Blended(font[size], natchars[ch-128], white);
|
txt = TTF_RenderUTF8_Blended(font[siz], natchars[ch-128], white);
|
||||||
}
|
}
|
||||||
if(txt == NULL) continue;
|
if(txt == NULL) continue;
|
||||||
#if CAP_CREATEFONT
|
#if CAP_CREATEFONT
|
||||||
@ -481,7 +494,7 @@ void init_glfont(int size) {
|
|||||||
|
|
||||||
int gl_width(int size, const char *s) {
|
int gl_width(int size, const char *s) {
|
||||||
int gsiz = size;
|
int gsiz = size;
|
||||||
if(size > vid.fsize || size > 72) gsiz = 72;
|
if(size > vid.fsize || size > max_glfont_size) gsiz = max_glfont_size;
|
||||||
|
|
||||||
#if CAP_FIXEDSIZE
|
#if CAP_FIXEDSIZE
|
||||||
gsiz = CAP_FIXEDSIZE;
|
gsiz = CAP_FIXEDSIZE;
|
||||||
@ -514,7 +527,7 @@ glhr::textured_vertex charvertex(int x1, int y1, ld tx, ld ty) {
|
|||||||
|
|
||||||
bool gl_print(int x, int y, int shift, int size, const char *s, color_t color, int align) {
|
bool gl_print(int x, int y, int shift, int size, const char *s, color_t color, int align) {
|
||||||
int gsiz = size;
|
int gsiz = size;
|
||||||
if(size > vid.fsize || size > 72) gsiz = 72;
|
if(size > vid.fsize || size > max_glfont_size) gsiz = max_glfont_size;
|
||||||
|
|
||||||
#if CAP_FIXEDSIZE
|
#if CAP_FIXEDSIZE
|
||||||
gsiz = CAP_FIXEDSIZE;
|
gsiz = CAP_FIXEDSIZE;
|
||||||
@ -584,7 +597,7 @@ EX void resetGL() {
|
|||||||
DEBBI(DF_INIT | DF_GRAPH, ("reset GL"))
|
DEBBI(DF_INIT | DF_GRAPH, ("reset GL"))
|
||||||
callhooks(hooks_resetGL);
|
callhooks(hooks_resetGL);
|
||||||
#if CAP_GLFONT
|
#if CAP_GLFONT
|
||||||
for(int i=0; i<128; i++) if(glfont[i]) {
|
for(int i=0; i<max_glfont_size; i++) if(glfont[i]) {
|
||||||
delete glfont[i];
|
delete glfont[i];
|
||||||
glfont[i] = NULL;
|
glfont[i] = NULL;
|
||||||
}
|
}
|
||||||
@ -702,6 +715,7 @@ EX bool displaystr(int x, int y, int shift, int size, const char *str, color_t c
|
|||||||
|
|
||||||
col.r >>= darken; col.g >>= darken; col.b >>= darken;
|
col.r >>= darken; col.g >>= darken; col.b >>= darken;
|
||||||
|
|
||||||
|
fix_font_size(size);
|
||||||
loadfont(size);
|
loadfont(size);
|
||||||
|
|
||||||
SDL_Surface *txt = ((vid.antialias & AA_FONT)?TTF_RenderUTF8_Blended:TTF_RenderUTF8_Solid)(font[size], str, col);
|
SDL_Surface *txt = ((vid.antialias & AA_FONT)?TTF_RenderUTF8_Blended:TTF_RenderUTF8_Solid)(font[size], str, col);
|
||||||
|
2
hud.cpp
2
hud.cpp
@ -518,7 +518,7 @@ EX void drawStats() {
|
|||||||
rows = 0;
|
rows = 0;
|
||||||
while((buttonsize = minsize - vid.killreduction)) {
|
while((buttonsize = minsize - vid.killreduction)) {
|
||||||
columns = colspace / buttonsize;
|
columns = colspace / buttonsize;
|
||||||
rows = rowspace / buttonsize;
|
rows = rowspace / buttonsize; if(!rows) return;
|
||||||
int coltaken = 0;
|
int coltaken = 0;
|
||||||
for(int z=0; z<4; z++) {
|
for(int z=0; z<4; z++) {
|
||||||
if(z == 2 && !portrait) {
|
if(z == 2 && !portrait) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user