From c4eaac6d4856d4136b31f7db6e3974c6d846db4d Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 2 Jun 2026 19:04:14 +0200 Subject: [PATCH] Fonts: fixed an issue where passing a manually created ImFontAtlas to CreateContext() would incorrectly destroy it in DestroyContext() when ref-count gets back to zero. (#9426) # Conflicts: # docs/CHANGELOG.txt --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 9c3c8e68b..4f8cf7054 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -60,6 +60,8 @@ Other Changes: disable embedding either fonts separately. (#9407) - Tweak `CalcTextSize()` awkward width rounding/ceiling code to reduce floating-point imprecisions altering the result by 1 even at relatively small width. (#791) + - Fixed an issue where passing a manually created ImFontAtlas to CreateContext() would + incorrectly destroy it in DestroyContext() when ref-count gets back to zero. (#9426) - DrawList: - Minor optimization to `AddLine()`, `AddLineH()`, `AddLineV()` functions. (#4091) - Added `ImDrawListFlags_TextNoPixelSnap` to disable snapping of AddText() diff --git a/imgui.cpp b/imgui.cpp index c56e9eff1..516bd9dec 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4476,7 +4476,7 @@ void ImGui::Shutdown() for (ImFontAtlas* atlas : g.FontAtlases) { UnregisterFontAtlas(atlas); - if (atlas->RefCount == 0) + if (atlas->RefCount == 0 && atlas->OwnerContext == &g) { atlas->Locked = false; IM_DELETE(atlas);