]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_draw.c
avoid NULL pointer access if a surface had an unsupported type
[xonotic/darkplaces.git] / gl_draw.c
index 6821819cdfd58a30e7d2d93ff30974f60f930d01..eca73b5f8d304252f0d77ff5b440f68df4b21cb2 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -334,7 +334,12 @@ cachepic_t *Draw_CachePic_Flags(const char *path, unsigned int cachepicflags)
                        if(!((pic->texflags ^ texflags) & ~(TEXF_COMPRESS))) // ignore TEXF_COMPRESS when comparing, because fallback pics remove the flag
                        {
                                if(!(cachepicflags & CACHEPICFLAG_NOTPERSISTENT))
-                                       pic->autoload = false; // persist it
+                               {
+                                       if(pic->tex)
+                                               pic->autoload = false; // persist it
+                                       else
+                                               goto reload; // load it below, and then persist
+                               }
                                return pic;
                        }
 
@@ -350,6 +355,7 @@ cachepic_t *Draw_CachePic_Flags(const char *path, unsigned int cachepicflags)
        pic->chain = cachepichash[hashkey];
        cachepichash[hashkey] = pic;
 
+reload:
        // check whether it is an dynamic texture (if so, we can directly use its texture handler)
        pic->tex = CL_GetDynTexture( path );
        // if so, set the width/height, too
@@ -715,7 +721,7 @@ void LoadFont(qboolean override, const char *name, dp_font_t *fnt, float scale,
 extern cvar_t developer_font;
 dp_font_t *FindFont(const char *title, qboolean allocate_new)
 {
-       int i;
+       int i, oldsize;
 
        // find font
        for(i = 0; i < dp_fonts.maxsize; ++i)
@@ -734,14 +740,18 @@ dp_font_t *FindFont(const char *title, qboolean allocate_new)
                        }
                }
                // if no any 'free' fonts - expand buffer
-               i = dp_fonts.maxsize;
+               oldsize = dp_fonts.maxsize;
                dp_fonts.maxsize = dp_fonts.maxsize + FONTS_EXPAND;
                if (developer_font.integer)
-                       Con_Printf("FindFont: enlarging fonts buffer (%i -> %i)\n", i, dp_fonts.maxsize);
-               dp_fonts.f = Mem_Realloc(fonts_mempool, dp_fonts.f, sizeof(dp_font_t) * dp_fonts.maxsize);
+                       Con_Printf("FindFont: enlarging fonts buffer (%i -> %i)\n", oldsize, dp_fonts.maxsize);
+               dp_fonts.f = (dp_font_t *)Mem_Realloc(fonts_mempool, dp_fonts.f, sizeof(dp_font_t) * dp_fonts.maxsize);
+               // relink ft2 structures
+               for(i = 0; i < oldsize; ++i)
+                       if (dp_fonts.f[i].ft2)
+                               dp_fonts.f[i].ft2->settings = &dp_fonts.f[i].settings;
                // register a font in first expanded slot
-               strlcpy(dp_fonts.f[i].title, title, sizeof(dp_fonts.f[i].title));
-               return &dp_fonts.f[i];
+               strlcpy(dp_fonts.f[oldsize].title, title, sizeof(dp_fonts.f[oldsize].title));
+               return &dp_fonts.f[oldsize];
        }
        return NULL;
 }
@@ -888,10 +898,28 @@ static void LoadFont_f(void)
                                        voffset = atof(Cmd_Argv(i));
                                continue;
                        }
+
+                       if (sizes == -1)
+                               continue; // no slot for other sizes
+
                        // parse one of sizes
                        sz = atof(Cmd_Argv(i));
                        if (sz > 0.001f && sz < 1000.0f) // do not use crap sizes
                        {
+                               // search for duplicated sizes
+                               int j;
+                               for (j=0; j<sizes; j++)
+                                       if (f->req_sizes[j] == sz)
+                                               break;
+                               if (j != sizes)
+                                       continue; // sz already in req_sizes, don't add it again
+
+                               if (sizes == MAX_FONT_SIZES)
+                               {
+                                       Con_Printf("Warning: specified more than %i different font sizes, exceding ones are ignored\n", MAX_FONT_SIZES);
+                                       sizes = -1;
+                                       continue;
+                               }
                                f->req_sizes[sizes] = sz;
                                sizes++;
                        }
@@ -1602,10 +1630,10 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma
                        }
                        if (!fontmap || (ch <= 0xFF && fontmap->glyphs[ch].image) || (ch >= 0xE000 && ch <= 0xE0FF))
                        {
-                               if (ch > 0xE000)
+                               if (ch >= 0xE000)
                                        ch -= 0xE000;
                                if (ch > 0xFF)
-                                       continue;
+                                       goto out;
                                if (fontmap)
                                {
                                        if (map != ft2_oldstyle_map)
@@ -1733,6 +1761,7 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma
                                //prevmap = map;
                                prevch = ch;
                        }
+out:
                        if (shadow)
                        {
                                x -= 1.0/pix_x * r_textshadow.value;