Fonts, Context: assert that ImFontAtlas has no other references when destroying an owned atlas. (#9426)

This commit is contained in:
ocornut 2026-07-02 15:02:59 +02:00
parent 6824e2c2e4
commit 8fc25800e0
2 changed files with 8 additions and 3 deletions

View File

@ -95,6 +95,7 @@ Other Changes:
calling ClearFonts() during rendering. calling ClearFonts() during rendering.
- Fixed an issue where passing a manually created ImFontAtlas to CreateContext() would - 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) 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: - Nav:
- Fixed context menu activation with gamepad erroneously testing for _NavEnableKeyboard - Fixed context menu activation with gamepad erroneously testing for _NavEnableKeyboard
instead of _NavEnableGamepad. (#9454, #8803, #9270) [@Clownacy] instead of _NavEnableGamepad. (#9454, #8803, #9270) [@Clownacy]

View File

@ -4495,12 +4495,16 @@ void ImGui::Shutdown()
for (ImFontAtlas* atlas : g.FontAtlases) for (ImFontAtlas* atlas : g.FontAtlases)
{ {
UnregisterFontAtlas(atlas); UnregisterFontAtlas(atlas);
if (atlas->RefCount == 0 && atlas->OwnerContext == &g) if (atlas->OwnerContext == &g)
{
IM_ASSERT(atlas->RefCount == 0 && "Destroying context owning a ImFontAtlas which is still used elsewhere!");
if (atlas->RefCount == 0)
{ {
atlas->Locked = false; atlas->Locked = false;
IM_DELETE(atlas); IM_DELETE(atlas);
} }
} }
}
g.DrawListSharedData.TempBuffer.clear(); g.DrawListSharedData.TempBuffer.clear();
// Cleanup of other data are conditional on actually having initialized Dear ImGui. // Cleanup of other data are conditional on actually having initialized Dear ImGui.