]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
uncomment code that prevents memory leak in LoadFont; better English
authorNaitLee <naitli@foxmail.com>
Sat, 16 Sep 2023 06:17:35 +0000 (14:17 +0800)
committerbones_was_here <bones_was_here@xonotic.au>
Thu, 4 Jan 2024 01:32:08 +0000 (11:32 +1000)
Signed-off-by: NaitLee <naitli@foxmail.com>
ft2.c
ft2_fontdefs.h
gl_draw.c

diff --git a/ft2.c b/ft2.c
index 337ce5f86a626819ccdca1105b49e136db615c75..0b1f9dcc111abc0288ad03f8bf101290d805c8e8 100644 (file)
--- 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
index 821196a4969e3d63be0d13909855dbdbd0bd5539..68956b9082d6682c42c7b8492bd2801155071502 100644 (file)
@@ -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
index 73578622da3661e14f6a2263b963c896e9c6640b..eb8630a0b6331a05180b8e0d3627c5efcf23e97f 100644 (file)
--- 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)
        {