Fix crash due to font changes refactor

#2260
This commit is contained in:
Wojtek Figat
2024-02-19 22:14:39 +01:00
parent 504a997f12
commit db65b8037d
2 changed files with 7 additions and 3 deletions

View File

@@ -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);

View File

@@ -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<int16>(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<float>(slot->Width - 2 * padding);
entry.UVSize.Y = static_cast<float>(slot->Height - 2 * padding);
entry.Slot = slot;
entry.Font = font;
return false;
}