Fix crash on using Space char in font with no font atlases initialized
This commit is contained in:
@@ -109,7 +109,7 @@ void FontManagerService::Dispose()
|
|||||||
|
|
||||||
FontTextureAtlas* FontManager::GetAtlas(int32 index)
|
FontTextureAtlas* FontManager::GetAtlas(int32 index)
|
||||||
{
|
{
|
||||||
return Atlases[index];
|
return index >= 0 && index < Atlases.Count() ? Atlases.Get()[index] : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FontManager::AddNewEntry(Font* font, Char c, FontCharacterEntry& entry)
|
bool FontManager::AddNewEntry(Font* font, Char c, FontCharacterEntry& entry)
|
||||||
@@ -206,6 +206,7 @@ bool FontManager::AddNewEntry(Font* font, Char c, FontCharacterEntry& entry)
|
|||||||
// End for empty glyphs
|
// End for empty glyphs
|
||||||
if (GlyphImageData.IsEmpty())
|
if (GlyphImageData.IsEmpty())
|
||||||
{
|
{
|
||||||
|
entry.TextureIndex = MAX_uint8;
|
||||||
if (bitmap == &tmpBitmap)
|
if (bitmap == &tmpBitmap)
|
||||||
{
|
{
|
||||||
FT_Bitmap_Done(Library, bitmap);
|
FT_Bitmap_Done(Library, bitmap);
|
||||||
|
|||||||
@@ -1137,11 +1137,17 @@ void Render2D::DrawText(Font* font, const StringView& text, const Color& color,
|
|||||||
// Get texture atlas that contains current character
|
// Get texture atlas that contains current character
|
||||||
fontAtlasIndex = entry.TextureIndex;
|
fontAtlasIndex = entry.TextureIndex;
|
||||||
fontAtlas = FontManager::GetAtlas(fontAtlasIndex);
|
fontAtlas = FontManager::GetAtlas(fontAtlasIndex);
|
||||||
fontAtlas->EnsureTextureCreated();
|
if (fontAtlas)
|
||||||
drawCall.AsChar.Tex = fontAtlas->GetTexture();
|
{
|
||||||
|
fontAtlas->EnsureTextureCreated();
|
||||||
// Cache atlas inverted size (inverted to improve performance)
|
drawCall.AsChar.Tex = fontAtlas->GetTexture();
|
||||||
invAtlasSize = 1.0f / fontAtlas->GetSize();
|
invAtlasSize = 1.0f / fontAtlas->GetSize();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
drawCall.AsChar.Tex = nullptr;
|
||||||
|
invAtlasSize = 1.0f;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if character is a whitespace
|
// Check if character is a whitespace
|
||||||
@@ -1250,9 +1256,17 @@ void Render2D::DrawText(Font* font, const StringView& text, const Color& color,
|
|||||||
// Get texture atlas that contains current character
|
// Get texture atlas that contains current character
|
||||||
fontAtlasIndex = entry.TextureIndex;
|
fontAtlasIndex = entry.TextureIndex;
|
||||||
fontAtlas = FontManager::GetAtlas(fontAtlasIndex);
|
fontAtlas = FontManager::GetAtlas(fontAtlasIndex);
|
||||||
fontAtlas->EnsureTextureCreated();
|
if (fontAtlas)
|
||||||
invAtlasSize = 1.0f / fontAtlas->GetSize();
|
{
|
||||||
drawCall.AsChar.Tex = fontAtlas->GetTexture();
|
fontAtlas->EnsureTextureCreated();
|
||||||
|
invAtlasSize = 1.0f / fontAtlas->GetSize();
|
||||||
|
drawCall.AsChar.Tex = fontAtlas->GetTexture();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
invAtlasSize = 1.0f;
|
||||||
|
drawCall.AsChar.Tex = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get kerning
|
// Get kerning
|
||||||
|
|||||||
@@ -177,8 +177,15 @@ void TextRender::UpdateLayout()
|
|||||||
// Get texture atlas that contains current character
|
// Get texture atlas that contains current character
|
||||||
drawChunk.FontAtlasIndex = entry.TextureIndex;
|
drawChunk.FontAtlasIndex = entry.TextureIndex;
|
||||||
fontAtlas = FontManager::GetAtlas(drawChunk.FontAtlasIndex);
|
fontAtlas = FontManager::GetAtlas(drawChunk.FontAtlasIndex);
|
||||||
fontAtlas->EnsureTextureCreated();
|
if (fontAtlas)
|
||||||
invAtlasSize = 1.0f / fontAtlas->GetSize();
|
{
|
||||||
|
fontAtlas->EnsureTextureCreated();
|
||||||
|
invAtlasSize = 1.0f / fontAtlas->GetSize();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
invAtlasSize = 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
// Setup material
|
// Setup material
|
||||||
drawChunk.Material = Content::CreateVirtualAsset<MaterialInstance>();
|
drawChunk.Material = Content::CreateVirtualAsset<MaterialInstance>();
|
||||||
|
|||||||
Reference in New Issue
Block a user