Browse Source

Viewport, Platform: Update the contents of GetPlatformData() in EndFrame() so back-end can access it even if UpdatePlatformWindows hasn't been called. (#1542)

omar 7 years ago
parent
commit
9d5ec05150
1 changed files with 13 additions and 7 deletions
  1. 13 7
      imgui.cpp

+ 13 - 7
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);