From 61e985457d961aa192527b0c272100453a4e4f22 Mon Sep 17 00:00:00 2001 From: def Date: Wed, 30 Sep 2020 23:38:05 +0200 Subject: [PATCH] Clean up font buffers & texturedata --- src/engine/client/text.cpp | 45 +++++++++++++++++++------------------- src/engine/textrender.h | 1 - 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/engine/client/text.cpp b/src/engine/client/text.cpp index bfffdb03a..a80a98fe6 100644 --- a/src/engine/client/text.cpp +++ b/src/engine/client/text.cpp @@ -80,6 +80,17 @@ struct CFontSizeData class CFont { public: + ~CFont() + { + free(m_pBuf); + delete[] m_TextureData[0]; + delete[] m_TextureData[1]; + for(size_t i = 0; i < m_FtFallbackFonts.size(); i++) + { + free(m_FtFallbackFonts[i].m_pBuf); + } + } + void InitFontSizes() { for(int i = 0; i < NUM_FONT_SIZES; ++i) @@ -97,11 +108,13 @@ public: return &m_aFontSizes[FontSize - MIN_FONT_SIZE]; } + void *m_pBuf; char m_aFilename[512]; FT_Face m_FtFace; struct SFontFallBack { + void *m_pBuf; char m_aFilename[512]; FT_Face m_FtFace; }; @@ -584,7 +597,14 @@ public: { for(size_t i = 0; i < m_Fonts.size(); ++i) { - DestroyFont(m_Fonts[i]); + FT_Done_Face(m_Fonts[i]->m_FtFace); + + for(CFont::SFontFallBack &FallbackFont : m_Fonts[i]->m_FtFallbackFonts) + { + FT_Done_Face(FallbackFont.m_FtFace); + } + + delete m_Fonts[i]; } if(m_FTLibrary != 0) @@ -660,6 +680,7 @@ public: dbg_msg("textrender", "loaded pFont from '%s'", pFilename); + pFont->m_pBuf = (void *)pBuf; pFont->m_CurTextureDimensions[0] = 1024; pFont->m_TextureData[0] = new unsigned char[pFont->m_CurTextureDimensions[0] * pFont->m_CurTextureDimensions[0]]; mem_zero(pFont->m_TextureData[0], pFont->m_CurTextureDimensions[0] * pFont->m_CurTextureDimensions[0] * sizeof(unsigned char)); @@ -683,6 +704,7 @@ public: virtual bool LoadFallbackFont(CFont *pFont, const char *pFilename, const unsigned char *pBuf, size_t Size) { CFont::SFontFallBack FallbackFont; + FallbackFont.m_pBuf = (void *)pBuf; str_copy(FallbackFont.m_aFilename, pFilename, sizeof(FallbackFont.m_aFilename)); if(FT_New_Memory_Face(m_FTLibrary, pBuf, Size, 0, &FallbackFont.m_FtFace) == 0) @@ -715,27 +737,6 @@ public: return NULL; } - virtual void DestroyFont(CFont *pFont) - { - for(size_t i = 0; i < m_Fonts.size(); ++i) - { - if(m_Fonts[i] == pFont) - { - m_Fonts[i] = m_Fonts[m_Fonts.size() - 1]; - m_Fonts.pop_back(); - - FT_Done_Face(pFont->m_FtFace); - - for(CFont::SFontFallBack &FallbackFont : pFont->m_FtFallbackFonts) - { - FT_Done_Face(FallbackFont.m_FtFace); - } - - delete pFont; - } - } - } - virtual void SetDefaultFont(CFont *pFont) { dbg_msg("textrender", "default pFont set %p", pFont); diff --git a/src/engine/textrender.h b/src/engine/textrender.h index a81d3c522..efdc0dd46 100644 --- a/src/engine/textrender.h +++ b/src/engine/textrender.h @@ -82,7 +82,6 @@ public: virtual bool LoadFallbackFont(CFont *pFont, const char *pFilename, const unsigned char *pBuf, size_t Size) = 0; virtual CFont *GetFont(int FontIndex) = 0; virtual CFont *GetFont(const char *pFilename) = 0; - virtual void DestroyFont(CFont *pFont) = 0; virtual void SetDefaultFont(CFont *pFont) = 0; virtual void SetCurFont(CFont *pFont) = 0;