From 3c275a79e868dd127fbf711741289664f4dae9c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Ekstr=C3=B6m?= Date: Thu, 8 Jan 2026 03:05:05 +0100 Subject: [PATCH] Fixes issue with g_ContextMap outliving zgui --- libs/imgui/backends/imgui_impl_glfw.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libs/imgui/backends/imgui_impl_glfw.cpp b/libs/imgui/backends/imgui_impl_glfw.cpp index f1be83f..addadf9 100644 --- a/libs/imgui/backends/imgui_impl_glfw.cpp +++ b/libs/imgui/backends/imgui_impl_glfw.cpp @@ -808,6 +808,13 @@ void ImGui_ImplGlfw_Shutdown() io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad | ImGuiBackendFlags_PlatformHasViewports | ImGuiBackendFlags_HasMouseHoveredViewport); ImGui_ImplGlfw_ContextMap_Remove(bd->Window); IM_DELETE(bd); + + if (g_ContextMap.empty()) { + // zgui overrides the default allocator of imgui and memory allocated by g_ContextMap will belong to zgui. + // By freeing this memory now we avoid issues with the destructor freeing after zgui has been deinitialized. + g_ContextMap.clear(); + } + } static void ImGui_ImplGlfw_UpdateMouseData()