From 2cc4760ee56f0da55be8d336a83dd102b74f2b1a Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Thu, 15 Jun 2023 22:45:29 +0200 Subject: [PATCH] Add a function to dispose the fonts --- src/blupi.cxx | 1 + src/text.cxx | 30 ++++++++++++++++++++++++++---- src/text.h | 1 + 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/blupi.cxx b/src/blupi.cxx index 72ba750..9e2daa2 100644 --- a/src/blupi.cxx +++ b/src/blupi.cxx @@ -1116,6 +1116,7 @@ main (int argc, char * argv[]) Platform::run (HandleEvent); + DisposeFonts (); FinishObjects (); if (g_renderer) diff --git a/src/text.cxx b/src/text.cxx index 4d56c7d..9aedec4 100644 --- a/src/text.cxx +++ b/src/text.cxx @@ -68,9 +68,21 @@ struct TexText { ~TexText () { - SDL_DestroyTexture (this->outline); - SDL_DestroyTexture (this->base); - SDL_DestroyTexture (this->over); + if (this->outline) + { + SDL_DestroyTexture (this->outline); + this->outline = nullptr; + } + if (this->base) + { + SDL_DestroyTexture (this->base); + this->base = nullptr; + } + if (this->over) + { + SDL_DestroyTexture (this->over); + this->over = nullptr; + } } }; @@ -133,7 +145,7 @@ public: TTF_SetFontDirection (this->font, TTF_DIRECTION_RTL); } - ~Font () { TTF_CloseFont (this->font); } + ~Font () { this->cache.Clear (); TTF_CloseFont (this->font); } TTF_Font * GetFont () { return this->font; } @@ -379,6 +391,10 @@ public: } ~Fonts () + { + } + + void Clear () { delete this->latinLittle; delete this->latinRed; @@ -654,6 +670,12 @@ GetFonts () return &fonts; } +void +DisposeFonts () +{ + GetFonts ()->Clear (); +} + /** * \brief Draw a text in a pixmap to a specific position. * diff --git a/src/text.h b/src/text.h index 09bb986..59edaf1 100644 --- a/src/text.h +++ b/src/text.h @@ -30,6 +30,7 @@ class Fonts; Fonts * GetFonts (); +void DisposeFonts (); void DrawText ( CPixmap * pPixmap, Point pos, const char * pText, Sint32 font = 0,