diff --git a/imgui.cpp b/imgui.cpp index a45381c5..df7961fd 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3483,10 +3483,6 @@ void ImGui::UpdatePlatformWindows() IM_ASSERT(g.FrameCountEnded == g.FrameCount && "Forgot to call Render() or EndFrame() before UpdatePlatformWindows()?"); IM_ASSERT(g.FrameCountPlatformEnded < g.FrameCount); g.FrameCountPlatformEnded = g.FrameCount; - - g.PlatformData.MainViewport = g.Viewports[0]; - g.PlatformData.Viewports.resize(0); - g.PlatformData.Viewports.push_back(g.Viewports[0]); if (!(g.IO.ConfigFlags & ImGuiConfigFlags_EnableViewports)) return; @@ -3508,9 +3504,6 @@ void ImGui::UpdatePlatformWindows() continue; } - g.PlatformData.Viewports.push_back(viewport); - IM_ASSERT(viewport->Window != NULL); - bool is_new_window = (viewport->PlatformHandle == NULL && viewport->PlatformUserData == NULL && viewport->RendererUserData == NULL); if (is_new_window && viewport->PlatformHandle == NULL && viewport->PlatformUserData == NULL) g.PlatformIO.Platform_CreateWindow(viewport); @@ -4417,6 +4410,19 @@ void ImGui::EndFrame() } } + // Update user-side viewport list + g.PlatformData.MainViewport = g.Viewports[0]; + g.PlatformData.Viewports.resize(0); + for (int i = 0; i < g.Viewports.Size; i++) + { + ImGuiViewportP* viewport = g.Viewports[i]; + if (viewport->LastFrameActive < g.FrameCount) + continue; + if (i > 0) + IM_ASSERT(viewport->Window != NULL); + g.PlatformData.Viewports.push_back(viewport); + } + // Sort the window list so that all child windows are after their parent // We cannot do that on FocusWindow() because childs may not exist yet g.WindowsSortBuffer.resize(0);