From db65b8037d8ffd59324a2015d5cba6cff57db26d Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 19 Feb 2024 22:14:39 +0100 Subject: [PATCH] Fix crash due to font changes refactor #2260 --- Source/Engine/Render2D/Font.cpp | 1 + Source/Engine/Render2D/FontManager.cpp | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Source/Engine/Render2D/Font.cpp b/Source/Engine/Render2D/Font.cpp index 71eca1f59..973bf21e3 100644 --- a/Source/Engine/Render2D/Font.cpp +++ b/Source/Engine/Render2D/Font.cpp @@ -62,6 +62,7 @@ void Font::GetCharacter(Char c, FontCharacterEntry& result, bool enableFallback) // Create character cache FontManager::AddNewEntry(this, c, result); + ASSERT(result.Font); // Add to the dictionary _characters.Add(c, result); diff --git a/Source/Engine/Render2D/FontManager.cpp b/Source/Engine/Render2D/FontManager.cpp index 2e1ba8c6b..7aef7098e 100644 --- a/Source/Engine/Render2D/FontManager.cpp +++ b/Source/Engine/Render2D/FontManager.cpp @@ -161,6 +161,12 @@ bool FontManager::AddNewEntry(Font* font, Char c, FontCharacterEntry& entry) } #endif + // Init the character data + Platform::MemoryClear(&entry, sizeof(entry)); + entry.Character = c; + entry.Font = font; + entry.IsValid = false; + // Load the glyph const FT_Error error = FT_Load_Glyph(face, glyphIndex, glyphFlags); if (error) @@ -195,8 +201,6 @@ bool FontManager::AddNewEntry(Font* font, Char c, FontCharacterEntry& entry) ASSERT(bitmap && bitmap->pixel_mode == FT_PIXEL_MODE_GRAY); // Fill the character data - Platform::MemoryClear(&entry, sizeof(entry)); - entry.Character = c; entry.AdvanceX = Convert26Dot6ToRoundedPixel(glyph->advance.x); entry.OffsetY = glyph->bitmap_top; entry.OffsetX = glyph->bitmap_left; @@ -289,7 +293,6 @@ bool FontManager::AddNewEntry(Font* font, Char c, FontCharacterEntry& entry) entry.UVSize.X = static_cast(slot->Width - 2 * padding); entry.UVSize.Y = static_cast(slot->Height - 2 * padding); entry.Slot = slot; - entry.Font = font; return false; }