Fonts: adding new fonts after removing all fonts mid-frame properly updates current state.
diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 4324c69..63235b2 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt
@@ -128,6 +128,7 @@ is enabled, creating side-effects when later disabling hinting or dynamically switching to stb_truetype rasterizer. - Post rescale GlyphOffset is always rounded. + - Adding new fonts after removing all fonts mid-frame properly updates current state. - Textures: - Fixed a building issue when ImTextureID is defined as a struct. - Fixed displaying texture # in Metrics/Debugger window.
diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 780f6b8..9889b28 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp
@@ -3035,6 +3035,7 @@ ImFontAtlasBuildInit(this); // Create new font + const bool is_first_font = (Fonts.Size == 0); ImFont* font; if (!font_cfg_in->MergeMode) { @@ -3092,6 +3093,8 @@ } ImFontAtlasFontSourceAddToFont(this, font, font_cfg); + if (is_first_font) + ImFontAtlasBuildNotifySetFont(this, NULL, font); return font; } @@ -3254,6 +3257,9 @@ shared_data->Font = new_font; if (ImGuiContext* ctx = shared_data->Context) { + if (ctx->FrameCount == 0 && old_font == NULL) // While this should work either way, we save ourselves the bother / debugging confusion of running ImGui code so early when it is not needed. + continue; + if (ctx->IO.FontDefault == old_font) ctx->IO.FontDefault = new_font; if (ctx->Font == old_font)