Skip to content

Commit 59bd316

Browse files
committed
[graf2d] Further simplify freetype resource cleanup.
In looking for a memory leak (which turned out to be a freetype issue [1]), it became evident that TTGlyph can actually handle its own cleanup, allowing for simplifying the code. [1] https://gitlab.freedesktop.org/freetype/freetype/-/work_items/1399
1 parent 4415906 commit 59bd316

2 files changed

Lines changed: 6 additions & 11 deletions

File tree

graf2d/graf/inc/TTF.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class TTF {
6868
FT_Vector fPos; ///< position of glyph origin
6969
FT_Glyph fImage{nullptr}; ///< glyph image
7070
TTGlyph(UInt_t indx = 0) : fIndex(indx) {}
71+
~TTGlyph();
7172
};
7273

7374
TTF() {}

graf2d/graf/src/TTF.cxx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ const Float_t kScale = 0.93376068;
3535
Bool_t TTFhandle::fgHinting = kFALSE;
3636
Bool_t TTFhandle::fgSmoothing = kTRUE;
3737

38+
/// Free all resources of this glyph.
39+
TTF::TTGlyph::~TTGlyph()
40+
{
41+
FT_Done_Glyph(fImage);
42+
}
3843

3944
struct TTFontHandle {
4045
std::string name;
@@ -67,8 +72,6 @@ struct TTFhandle::FT_Library_Wrapper {
6772
return _library;
6873
}
6974

70-
bool InitCompleted() const { return _library != nullptr; }
71-
7275
~FT_Library_Wrapper()
7376
{
7477
if (_library)
@@ -278,15 +281,6 @@ FT_BitmapGlyph TTFhandle::GetGlyphBitmap(UInt_t n, Bool_t smooth)
278281

279282
void TTFhandle::CleanupGlyphs()
280283
{
281-
bool is_lib = fFT_Library.InitCompleted();
282-
283-
for(auto &glyph : fGlyphs) {
284-
// clear existing image if there is one
285-
if (glyph.fImage && is_lib) {
286-
FT_Done_Glyph(glyph.fImage);
287-
glyph.fImage = nullptr;
288-
}
289-
}
290284
fGlyphs.clear();
291285
}
292286

0 commit comments

Comments
 (0)