From c3f20f6b81cd2fd3be2b9073cba089d7c3093740 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 13 Mar 2019 11:27:30 +0100 Subject: [PATCH] Viewport: DestroyPlatformWindow() skips calling user function if PlatformWindowCreated is set. + Clarified comment about implicit Debug viewport which may be hogging a viewport. --- imgui.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 4b1b9f77..89b55356 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -10446,7 +10446,8 @@ void ImGui::UpdatePlatformWindows() { ImGuiViewportP* viewport = g.Viewports[i]; - // Destroy platform window if the viewport hasn't been submitted or if it is hosting a hidden window (the implicit/fallback Debug window will be registered its viewport then be disabled) + // Destroy platform window if the viewport hasn't been submitted or if it is hosting a hidden window + // (the implicit/fallback Debug##Default window will be registering its viewport then be disabled, causing a dummy DestroyPlatformWindow to be made each frame) bool destroy_platform_window = false; destroy_platform_window |= (viewport->LastFrameActive < g.FrameCount - 1); destroy_platform_window |= (viewport->Window && !IsWindowActiveAndVisible(viewport->Window)); @@ -10628,15 +10629,20 @@ static void ImGui::UpdateViewportPlatformMonitor(ImGuiViewportP* viewport) void ImGui::DestroyPlatformWindow(ImGuiViewportP* viewport) { ImGuiContext& g = *GImGui; - if (g.PlatformIO.Renderer_DestroyWindow) - g.PlatformIO.Renderer_DestroyWindow(viewport); - if (g.PlatformIO.Platform_DestroyWindow) - g.PlatformIO.Platform_DestroyWindow(viewport); - IM_ASSERT(viewport->RendererUserData == NULL); - IM_ASSERT(viewport->PlatformUserData == NULL); - viewport->PlatformHandle = NULL; - viewport->RendererUserData = viewport->PlatformHandle = NULL; - viewport->PlatformWindowCreated = false; + if (viewport->PlatformWindowCreated) + { + if (g.PlatformIO.Renderer_DestroyWindow) + g.PlatformIO.Renderer_DestroyWindow(viewport); + if (g.PlatformIO.Platform_DestroyWindow) + g.PlatformIO.Platform_DestroyWindow(viewport); + IM_ASSERT(viewport->RendererUserData == NULL && viewport->PlatformUserData == NULL); + viewport->PlatformWindowCreated = false; + } + else + { + IM_ASSERT(viewport->RendererUserData == NULL && viewport->PlatformUserData == NULL && viewport->PlatformHandle == NULL); + } + viewport->RendererUserData = viewport->PlatformUserData = viewport->PlatformHandle = NULL; viewport->ClearRequestFlags(); }