From 8fc25800e0f4164c6edc4e9b00cc0e8d988d3b3c Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 2 Jul 2026 15:02:59 +0200 Subject: [PATCH] Fonts, Context: assert that ImFontAtlas has no other references when destroying an owned atlas. (#9426) --- docs/CHANGELOG.txt | 1 + imgui.cpp | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 1119b7ab6..aca07b0ad 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -95,6 +95,7 @@ Other Changes: calling ClearFonts() during rendering. - 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) + - Destroying an ImGui context using a ImFontAtlas checks that the later has no references. - Nav: - Fixed context menu activation with gamepad erroneously testing for _NavEnableKeyboard instead of _NavEnableGamepad. (#9454, #8803, #9270) [@Clownacy] diff --git a/imgui.cpp b/imgui.cpp index a7d03caa4..2feefc854 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4495,10 +4495,14 @@ void ImGui::Shutdown() for (ImFontAtlas* atlas : g.FontAtlases) { UnregisterFontAtlas(atlas); - if (atlas->RefCount == 0 && atlas->OwnerContext == &g) + if (atlas->OwnerContext == &g) { - atlas->Locked = false; - IM_DELETE(atlas); + IM_ASSERT(atlas->RefCount == 0 && "Destroying context owning a ImFontAtlas which is still used elsewhere!"); + if (atlas->RefCount == 0) + { + atlas->Locked = false; + IM_DELETE(atlas); + } } } g.DrawListSharedData.TempBuffer.clear();