From 505ff536f9393ddfcce4a06017131e7c3955027f Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 31 Oct 2025 16:37:42 +0100 Subject: [PATCH] Textures: fixed an issue preventing multi-contexts from using each others' fonts if context 2 runs after context 1's Render() function. (#9039) --- docs/CHANGELOG.txt | 3 +++ imgui_draw.cpp | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index f7f8b94a1..7b101d6a7 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -60,6 +60,9 @@ Other Changes: resizing the parent window while keeping the multi-line field active (which is most typically achieved when resizing programmatically or via a docking layout reacting to a platform window resize). (#3237, #9007) [@anton-kl, @ocornut] +- Textures: + - Fixed an issue preventing multi-contexts from using each others' fonts + if context 2 runs after context 1's Render() function. (#9039) - MultiSelect: added ImGuiMultiSelectFlags_NoSelectOnRightClick to disable default right-click processing, which selects item on mouse down and is designed for context-menus. (#8200, #9015) diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 55f105294..9e6babf78 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -3909,6 +3909,11 @@ void ImFontAtlasRemoveDrawListSharedData(ImFontAtlas* atlas, ImDrawListSharedDat void ImFontAtlasUpdateDrawListsTextures(ImFontAtlas* atlas, ImTextureRef old_tex, ImTextureRef new_tex) { for (ImDrawListSharedData* shared_data : atlas->DrawListSharedDatas) + { + // If Context 2 uses font owned by Context 1 which already called EndFrame()/Render(), we don't want to mess with draw commands for Context 1 + if (shared_data->Context && !shared_data->Context->WithinFrameScope) + continue; + for (ImDrawList* draw_list : shared_data->DrawLists) { // Replace in command-buffer @@ -3922,6 +3927,7 @@ void ImFontAtlasUpdateDrawListsTextures(ImFontAtlas* atlas, ImTextureRef old_tex if (stacked_tex == old_tex) stacked_tex = new_tex; } + } } // Update texture coordinates in all draw list shared context