Viewport: DestroyPlatformWindows() checks for the bool CreatedPlatformWindow flag correctly. Note that we set CreatedPlatformWindow=true for the main viewport to allow the back-end to store data in the public Viewport structure (for consistency). (#1542)

This commit is contained in:
omar 2018-08-15 16:07:07 -07:00
parent 9852649e97
commit 5d630c930d
2 changed files with 14 additions and 9 deletions

View File

@ -137,7 +137,7 @@ int main(int, char**)
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
//io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons; //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons;
//io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge; //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge;
io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleFonts; io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleFonts; // FIXME-DPI: THIS CURRENTLY DOESN'T WORK AS EXPECTED. DON'T USE IN USER APP!
io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleViewports; io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleViewports;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls

View File

@ -4599,6 +4599,7 @@ void ImGui::Initialize(ImGuiContext* context)
ImGuiViewportP* viewport = IM_NEW(ImGuiViewportP)(); ImGuiViewportP* viewport = IM_NEW(ImGuiViewportP)();
viewport->ID = IMGUI_VIEWPORT_DEFAULT_ID; viewport->ID = IMGUI_VIEWPORT_DEFAULT_ID;
viewport->Idx = 0; viewport->Idx = 0;
viewport->CreatedPlatformWindow = true; // Set this flag so DestroyPlatformWindows() gives a chance for backend to receive DestroyWindow calls for the main viewport.
g.Viewports.push_back(viewport); g.Viewports.push_back(viewport);
g.PlatformIO.MainViewport = g.Viewports[0]; // Make it accessible in public-facing GetPlatformIO() immediately (before the first call to EndFrame) g.PlatformIO.MainViewport = g.Viewports[0]; // Make it accessible in public-facing GetPlatformIO() immediately (before the first call to EndFrame)
g.PlatformIO.Viewports.push_back(g.Viewports[0]); g.PlatformIO.Viewports.push_back(g.Viewports[0]);
@ -4608,16 +4609,20 @@ void ImGui::Initialize(ImGuiContext* context)
void ImGui::DestroyPlatformWindows() void ImGui::DestroyPlatformWindows()
{ {
// We call the destroy window on the main viewport (index 0) to give a chance to the back-end to clear any data it may hold on it. // We call the destroy window on the main viewport (index 0) to give a chance to the back-end to clear any data
// have stored in e.g. PlatformHandle.
// It is expected that the back-end stored a flag to remember that it doesn't own the window created for the main viewport, // It is expected that the back-end stored a flag to remember that it doesn't own the window created for the main viewport,
// and won't destroy the underlying platform/renderer data. // and won't destroy the underlying platform/renderer data (e.g.
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
if (g.PlatformIO.Renderer_DestroyWindow) for (int i = 0; i < g.Viewports.Size; i++)
for (int i = 0; i < g.Viewports.Size; i++) if (g.Viewports[i]->CreatedPlatformWindow)
g.PlatformIO.Renderer_DestroyWindow(g.Viewports[i]); {
if (g.PlatformIO.Platform_DestroyWindow) if (g.PlatformIO.Renderer_DestroyWindow)
for (int i = 0; i < g.Viewports.Size; i++) g.PlatformIO.Renderer_DestroyWindow(g.Viewports[i]);
g.PlatformIO.Platform_DestroyWindow(g.Viewports[i]); if (g.PlatformIO.Platform_DestroyWindow)
g.PlatformIO.Platform_DestroyWindow(g.Viewports[i]);
g.Viewports[i]->CreatedPlatformWindow = false;
}
} }
// This function is merely here to free heap allocations. // This function is merely here to free heap allocations.