From: vortex Date: Fri, 22 Oct 2010 21:56:14 +0000 (+0000) Subject: Fix nasty bug with dp_fonts structure expanding, once dp_fonts.f being reallocated... X-Git-Tag: xonotic-v0.1.0preview~56^2~58 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=58f3c6005dba620506c939db3acb94a0e5bf1dcb;p=xonotic%2Fdarkplaces.git Fix nasty bug with dp_fonts structure expanding, once dp_fonts.f being reallocated, their corresponding ft2 settings links was messed up causing crash or postprocess to be lost. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10559 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/gl_draw.c b/gl_draw.c index 5c06e493..ec9392de 100644 --- a/gl_draw.c +++ b/gl_draw.c @@ -721,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) @@ -740,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); + 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; }