Skip to content

Commit

Permalink
imgui: ignore invalid fonts when merging
Browse files Browse the repository at this point in the history
Avoid crashing in release mode if a merged font is invalid or FontNo
can't be found. The font is simply ignored and the glyph range isn't
loaded.
Fixes MINIDUMP-4TD
  • Loading branch information
flyinghead committed Oct 21, 2024
1 parent c86ed29 commit b0403ed
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion core/deps/imgui/imgui_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2773,6 +2773,9 @@ static bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
dst_tmp_array.resize(atlas->Fonts.Size);
memset(src_tmp_array.Data, 0, (size_t)src_tmp_array.size_in_bytes());
memset(dst_tmp_array.Data, 0, (size_t)dst_tmp_array.size_in_bytes());
ImVector<bool> src_tmp_array_skip;
src_tmp_array_skip.resize(atlas->ConfigData.Size);
memset(src_tmp_array_skip.Data, 0, (size_t)src_tmp_array_skip.size_in_bytes());

// 1. Initialize font loading structure, check font data validity
for (int src_i = 0; src_i < atlas->ConfigData.Size; src_i++)
Expand All @@ -2797,7 +2800,8 @@ static bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
if (!stbtt_InitFont(&src_tmp.FontInfo, (unsigned char*)cfg.FontData, font_offset))
{
IM_ASSERT(0 && "stbtt_InitFont(): failed to parse FontData. It is correct and complete? Check FontDataSize.");
return false;
src_tmp_array_skip[src_i] = true;
continue;
}

// Measure highest codepoints
Expand All @@ -2818,6 +2822,8 @@ static bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
int total_glyphs_count = 0;
for (int src_i = 0; src_i < src_tmp_array.Size; src_i++)
{
if (src_tmp_array_skip[src_i])
continue;
ImFontBuildSrcData& src_tmp = src_tmp_array[src_i];
ImFontBuildDstData& dst_tmp = dst_tmp_array[src_tmp.DstIndex];
src_tmp.GlyphsSet.Create(src_tmp.GlyphsHighest + 1);
Expand All @@ -2844,6 +2850,8 @@ static bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
// 3. Unpack our bit map into a flat list (we now have all the Unicode points that we know are requested _and_ available _and_ not overlapping another)
for (int src_i = 0; src_i < src_tmp_array.Size; src_i++)
{
if (src_tmp_array_skip[src_i])
continue;
ImFontBuildSrcData& src_tmp = src_tmp_array[src_i];
src_tmp.GlyphsList.reserve(src_tmp.GlyphsCount);
UnpackBitVectorToFlatIndexList(&src_tmp.GlyphsSet, &src_tmp.GlyphsList);
Expand Down Expand Up @@ -2974,6 +2982,8 @@ static bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
// 9. Setup ImFont and glyphs for runtime
for (int src_i = 0; src_i < src_tmp_array.Size; src_i++)
{
if (src_tmp_array_skip[src_i])
continue;
// When merging fonts with MergeMode=true:
// - We can have multiple input fonts writing into a same destination font.
// - dst_font->ConfigData is != from cfg which is our source configuration.
Expand Down

0 comments on commit b0403ed

Please sign in to comment.