From c38526d14b38eff269032ac2b00a748ee16964c6 Mon Sep 17 00:00:00 2001 From: Anthony Pesch Date: Sun, 1 Oct 2017 23:40:29 -0400 Subject: [PATCH] Completely clear font when rebuilding atlas. Previously, IndexLookup was not cleared on each font, causing FindGlyph to return old glyphs when using MergeMode. --- imgui_draw.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 736476891..b45cc1ffd 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1540,7 +1540,6 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas) const float off_x = cfg.GlyphOffset.x; const float off_y = cfg.GlyphOffset.y + (float)(int)(dst_font->Ascent + 0.5f); - dst_font->FallbackGlyph = NULL; // Always clear fallback so FindGlyph can return NULL. It will be set again in BuildLookupTable() for (int i = 0; i < tmp.RangesCount; i++) { stbtt_pack_range& range = tmp.Ranges[i]; @@ -1582,14 +1581,16 @@ void ImFontAtlasBuildSetupFont(ImFontAtlas* atlas, ImFont* font, ImFontConfig* f { if (!font_config->MergeMode) { - font->ContainerAtlas = atlas; - font->ConfigData = font_config; - font->ConfigDataCount = 0; + ImVec2 display_offset = font->DisplayOffset; + + font->Clear(); + font->FontSize = font_config->SizePixels; + font->DisplayOffset = display_offset; + font->ConfigData = font_config; + font->ContainerAtlas = atlas; font->Ascent = ascent; font->Descent = descent; - font->Glyphs.resize(0); - font->MetricsTotalSurface = 0; } font->ConfigDataCount++; }