From f64c7c37efd9b0cead78e84f9378398b68ae5f61 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 12 Jan 2026 18:17:38 +0100 Subject: [PATCH] Fonts: fixed a crash when trying to use AddFont() with MergeMode=true on a font that has already been rendered. (#9162) --- docs/CHANGELOG.txt | 2 ++ imgui_draw.cpp | 1 + 2 files changed, 3 insertions(+) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index b7b4f2cd9..cd9315352 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -74,6 +74,8 @@ Breaking Changes: until a shutdown of the owning context or font atlas. - The fact that handling of `FontDataOwnedByAtlas = false` was broken bypassed the issue altogether. + - Fixed a crash when trying to use AddFont() with MergeMode=true on a font that + has already been rendered. (#9162) [@ocornut, @cyfewlp] - Removed ImFontConfig::PixelSnapV added in 1.92 which turns out is unnecessary (and misdocumented). Post-rescale GlyphOffset is always rounded. - Popups: changed compile-time 'ImGuiPopupFlags popup_flags = 1' default value to be '= 0' for diff --git a/imgui_draw.cpp b/imgui_draw.cpp index b839291b0..780f6b844 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -3049,6 +3049,7 @@ ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg_in) { IM_ASSERT(Fonts.Size > 0 && "Cannot use MergeMode for the first font"); // When using MergeMode make sure that a font has already been added before. font = font_cfg_in->DstFont ? font_cfg_in->DstFont : Fonts.back(); + ImFontAtlasFontDiscardBakes(this, font, 0); // Need to discard bakes if the font was already used, because baked->FontLoaderDatas[] will change size. (#9162) } // Add to list