From e3d45548f64b0573565924d30c0abe238c25ec34 Mon Sep 17 00:00:00 2001 From: NaitLee Date: Sat, 16 Sep 2023 14:17:35 +0800 Subject: [PATCH] uncomment code that prevents memory leak in LoadFont; better English Signed-off-by: NaitLee --- ft2.c | 12 ++++++------ ft2_fontdefs.h | 2 +- gl_draw.c | 6 +----- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/ft2.c b/ft2.c index 337ce5f8..0b1f9dcc 100644 --- a/ft2.c +++ b/ft2.c @@ -32,11 +32,11 @@ static int img_fontmap[256] = { * http://www.unicode.org/Public/UNIDATA/Blocks.txt * * Let's call these "bigblocks". - * These appears in a text in a "spreaded" way, ordinary maps will + * These characters are "spreaded", and ordinary maps will * waste huge amount of resources rendering/caching unused glyphs. * - * So, another matter is invented to counter this: incremental maps, - * in which only used glyphs may present. + * So, a new design is introduced to solve the problem: + * incremental maps, in which only used glyphs are stored. */ static const Uchar unicode_bigblocks[] = { 0x3400, 0x4DBF, // 6592 CJK Unified Ideographs Extension A @@ -53,7 +53,7 @@ CVars introduced with the freetype extension */ cvar_t r_font_disable_freetype = {CF_CLIENT | CF_ARCHIVE, "r_font_disable_freetype", "0", "disable freetype support for fonts entirely"}; -cvar_t r_font_use_alpha_textures = {CF_CLIENT | CF_ARCHIVE, "r_font_use_alpha_textures", "0", "[deprecated, not effective] use alpha-textures for font rendering, this should safe memory"}; +cvar_t r_font_use_alpha_textures = {CF_CLIENT | CF_ARCHIVE, "r_font_use_alpha_textures", "0", "[deprecated, not effective] use alpha-textures for font rendering, this should save memory"}; cvar_t r_font_size_snapping = {CF_CLIENT | CF_ARCHIVE, "r_font_size_snapping", "1", "stick to good looking font sizes whenever possible - bad when the mod doesn't support it!"}; cvar_t r_font_kerning = {CF_CLIENT | CF_ARCHIVE, "r_font_kerning", "1", "Use kerning if available"}; cvar_t r_font_diskcache = {CF_CLIENT | CF_ARCHIVE, "r_font_diskcache", "0", "[deprecated, not effective] save font textures to disk for future loading rather than generating them every time"}; @@ -1505,7 +1505,7 @@ static qbool Font_LoadMap(ft2_font_t *font, ft2_font_map_t *mapstart, Uchar _ch, map = (ft2_font_map_t *)Mem_Alloc(font_mempool, sizeof(ft2_font_map_t)); if (!map) { - Con_Printf(CON_ERROR "ERROR: Out of memory when allowcating fontmap for %s\n", font->name); + Con_Printf(CON_ERROR "ERROR: Out of memory when allocating fontmap for %s\n", font->name); return false; } @@ -1571,7 +1571,7 @@ static qbool Font_LoadMap(ft2_font_t *font, ft2_font_map_t *mapstart, Uchar _ch, incmap = mapstart->incmap = (font_incmap_t *)Mem_Alloc(font_mempool, sizeof(font_incmap_t)); if (!incmap) { - Con_Printf(CON_ERROR "ERROR: Out of memory when allowcating incremental fontmap for %s\n", font->name); + Con_Printf(CON_ERROR "ERROR: Out of memory when allocating incremental fontmap for %s\n", font->name); return false; } // this will be the startmap of incmap diff --git a/ft2_fontdefs.h b/ft2_fontdefs.h index 821196a4..68956b90 100644 --- a/ft2_fontdefs.h +++ b/ft2_fontdefs.h @@ -43,7 +43,7 @@ struct ft2_font_map_s glyph_slot_t glyphs[FONT_CHARS_PER_MAP]; Uchar glyphchars[FONT_CHARS_PER_MAP]; - // safes us the trouble of calculating these over and over again + // saves us the trouble of calculating these over and over again double sfx, sfy; // note: float width_of[256] was moved to `struct dp_font_s` as width_of_ft2 diff --git a/gl_draw.c b/gl_draw.c index 73578622..eb8630a0 100644 --- a/gl_draw.c +++ b/gl_draw.c @@ -354,17 +354,13 @@ void LoadFont(qbool override, const char *name, dp_font_t *fnt, float scale, flo if(drawtexturepool == NULL) return; // before gl_draw_start, so will be loaded later - /* - // this "reset" seems interrupts fontmap loading and wastes previous works - // no side-effects so far without this if(fnt->ft2) { - // clear freetype font + // clear previous freetype font to prevent leaking memory Font_UnloadFont(fnt->ft2); Mem_Free(fnt->ft2); fnt->ft2 = NULL; } - */ if(fnt->req_face != -1) { -- 2.39.2