Skip to content

Commit b0403ed

Browse files
committed
imgui: ignore invalid fonts when merging
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
1 parent c86ed29 commit b0403ed

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

core/deps/imgui/imgui_draw.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2773,6 +2773,9 @@ static bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
27732773
dst_tmp_array.resize(atlas->Fonts.Size);
27742774
memset(src_tmp_array.Data, 0, (size_t)src_tmp_array.size_in_bytes());
27752775
memset(dst_tmp_array.Data, 0, (size_t)dst_tmp_array.size_in_bytes());
2776+
ImVector<bool> src_tmp_array_skip;
2777+
src_tmp_array_skip.resize(atlas->ConfigData.Size);
2778+
memset(src_tmp_array_skip.Data, 0, (size_t)src_tmp_array_skip.size_in_bytes());
27762779

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

28032807
// Measure highest codepoints
@@ -2818,6 +2822,8 @@ static bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
28182822
int total_glyphs_count = 0;
28192823
for (int src_i = 0; src_i < src_tmp_array.Size; src_i++)
28202824
{
2825+
if (src_tmp_array_skip[src_i])
2826+
continue;
28212827
ImFontBuildSrcData& src_tmp = src_tmp_array[src_i];
28222828
ImFontBuildDstData& dst_tmp = dst_tmp_array[src_tmp.DstIndex];
28232829
src_tmp.GlyphsSet.Create(src_tmp.GlyphsHighest + 1);
@@ -2844,6 +2850,8 @@ static bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
28442850
// 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)
28452851
for (int src_i = 0; src_i < src_tmp_array.Size; src_i++)
28462852
{
2853+
if (src_tmp_array_skip[src_i])
2854+
continue;
28472855
ImFontBuildSrcData& src_tmp = src_tmp_array[src_i];
28482856
src_tmp.GlyphsList.reserve(src_tmp.GlyphsCount);
28492857
UnpackBitVectorToFlatIndexList(&src_tmp.GlyphsSet, &src_tmp.GlyphsList);
@@ -2974,6 +2982,8 @@ static bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
29742982
// 9. Setup ImFont and glyphs for runtime
29752983
for (int src_i = 0; src_i < src_tmp_array.Size; src_i++)
29762984
{
2985+
if (src_tmp_array_skip[src_i])
2986+
continue;
29772987
// When merging fonts with MergeMode=true:
29782988
// - We can have multiple input fonts writing into a same destination font.
29792989
// - dst_font->ConfigData is != from cfg which is our source configuration.

0 commit comments

Comments
 (0)