From cd79a91178d7815b0df8208d15e9897f4ac6747e Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 25 Nov 2025 21:38:18 +0100 Subject: [PATCH] Fix missing reference count for fallback font closes #16696 --- src/irrlicht_changes/CGUITTFont.cpp | 11 ++++++++--- src/irrlicht_changes/CGUITTFont.h | 5 +++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/irrlicht_changes/CGUITTFont.cpp b/src/irrlicht_changes/CGUITTFont.cpp index ed6b62adbd..038ddd4ba9 100644 --- a/src/irrlicht_changes/CGUITTFont.cpp +++ b/src/irrlicht_changes/CGUITTFont.cpp @@ -33,7 +33,6 @@ #include "CGUITTFont.h" -#include "irr_ptr.h" #include "log.h" #include "debug.h" #include "IGUIEnvironment.h" @@ -445,6 +444,12 @@ CGUITTGlyphPage* CGUITTFont::createGlyphPage(const u8 pixel_mode) return page; } +void CGUITTFont::setFallback(gui::IGUIFont *font) +{ + sanity_check(font != this); + fallback.grab(font); +} + void CGUITTFont::setMonochrome(const bool flag) { use_monochrome = flag; @@ -703,7 +708,7 @@ inline u32 CGUITTFont::getWidthFromCharacter(char32_t c) const int w = Glyphs[n-1].advance.X / 64; return w; } - if (fallback != 0) + if (fallback) { wchar_t s[] = { (wchar_t) c, 0 }; return fallback->getDimension(s).Width; @@ -723,7 +728,7 @@ inline u32 CGUITTFont::getHeightFromCharacter(char32_t c) const s32 height = (font_metrics.ascender / 64) - Glyphs[n-1].offset.Y + Glyphs[n-1].source_rect.getHeight(); return height; } - if (fallback != 0) + if (fallback) { wchar_t s[] = { (wchar_t) c, 0 }; return fallback->getDimension(s).Height; diff --git a/src/irrlicht_changes/CGUITTFont.h b/src/irrlicht_changes/CGUITTFont.h index 64dc5a3989..54dac5e6b8 100644 --- a/src/irrlicht_changes/CGUITTFont.h +++ b/src/irrlicht_changes/CGUITTFont.h @@ -36,6 +36,7 @@ #include #include +#include "irr_ptr.h" #include "IGUIEnvironment.h" #include "IGUIFont.h" #include "IVideoDriver.h" @@ -266,7 +267,7 @@ namespace gui u32 getLastGlyphPageIndex() const { return Glyph_Pages.size() - 1; } //! Set font that should be used for glyphs not present in ours - void setFallback(gui::IGUIFont* font) { fallback = font; } + void setFallback(gui::IGUIFont *font); inline s32 getAscender() const { return font_metrics.ascender; } @@ -329,7 +330,7 @@ namespace gui u32 shadow_offset = 0; u32 shadow_alpha = 0; - gui::IGUIFont *fallback = nullptr; + irr_ptr fallback; }; } // end namespace gui