From 9d5ec051501b96429ab75b37b8aeb0a7a9232ea7 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 19 Mar 2018 17:33:21 +0100 Subject: [PATCH] Viewport, Platform: Update the contents of GetPlatformData() in EndFrame() so back-end can access it even if UpdatePlatformWindows hasn't been called. (#1542) --- imgui.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index a45381c5c..df7961fd4 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);