diff --git a/examples/imgui_impl_dx10.cpp b/examples/imgui_impl_dx10.cpp index d88e2cc..014c4c3 100644 --- a/examples/imgui_impl_dx10.cpp +++ b/examples/imgui_impl_dx10.cpp @@ -611,6 +611,7 @@ void ImGui_ImplDX10_ShutdownPlatformInterface() { + ImGui::DestroyViewportsRendererData(ImGui::GetCurrentContext()); ImGuiIO& io = ImGui::GetIO(); memset(&io.RendererInterface, 0, sizeof(io.RendererInterface)); } diff --git a/examples/imgui_impl_dx10.cpp b/examples/imgui_impl_dx10.cpp index d88e2cc..014c4c3 100644 --- a/examples/imgui_impl_dx10.cpp +++ b/examples/imgui_impl_dx10.cpp @@ -611,6 +611,7 @@ void ImGui_ImplDX10_ShutdownPlatformInterface() { + ImGui::DestroyViewportsRendererData(ImGui::GetCurrentContext()); ImGuiIO& io = ImGui::GetIO(); memset(&io.RendererInterface, 0, sizeof(io.RendererInterface)); } diff --git a/examples/imgui_impl_dx11.cpp b/examples/imgui_impl_dx11.cpp index b7c26cd..56fc7f6 100644 --- a/examples/imgui_impl_dx11.cpp +++ b/examples/imgui_impl_dx11.cpp @@ -619,6 +619,7 @@ void ImGui_ImplDX11_ShutdownPlatformInterface() { + ImGui::DestroyViewportsRendererData(ImGui::GetCurrentContext()); ImGuiIO& io = ImGui::GetIO(); memset(&io.RendererInterface, 0, sizeof(io.RendererInterface)); } diff --git a/examples/imgui_impl_dx10.cpp b/examples/imgui_impl_dx10.cpp index d88e2cc..014c4c3 100644 --- a/examples/imgui_impl_dx10.cpp +++ b/examples/imgui_impl_dx10.cpp @@ -611,6 +611,7 @@ void ImGui_ImplDX10_ShutdownPlatformInterface() { + ImGui::DestroyViewportsRendererData(ImGui::GetCurrentContext()); ImGuiIO& io = ImGui::GetIO(); memset(&io.RendererInterface, 0, sizeof(io.RendererInterface)); } diff --git a/examples/imgui_impl_dx11.cpp b/examples/imgui_impl_dx11.cpp index b7c26cd..56fc7f6 100644 --- a/examples/imgui_impl_dx11.cpp +++ b/examples/imgui_impl_dx11.cpp @@ -619,6 +619,7 @@ void ImGui_ImplDX11_ShutdownPlatformInterface() { + ImGui::DestroyViewportsRendererData(ImGui::GetCurrentContext()); ImGuiIO& io = ImGui::GetIO(); memset(&io.RendererInterface, 0, sizeof(io.RendererInterface)); } diff --git a/examples/imgui_impl_dx12.cpp b/examples/imgui_impl_dx12.cpp index 7ed9a39..6de48c6 100644 --- a/examples/imgui_impl_dx12.cpp +++ b/examples/imgui_impl_dx12.cpp @@ -763,6 +763,7 @@ void ImGui_ImplDX12_ShutdownPlatformInterface() { + ImGui::DestroyViewportsRendererData(ImGui::GetCurrentContext()); ImGuiIO& io = ImGui::GetIO(); memset(&io.RendererInterface, 0, sizeof(io.RendererInterface)); } diff --git a/examples/imgui_impl_dx10.cpp b/examples/imgui_impl_dx10.cpp index d88e2cc..014c4c3 100644 --- a/examples/imgui_impl_dx10.cpp +++ b/examples/imgui_impl_dx10.cpp @@ -611,6 +611,7 @@ void ImGui_ImplDX10_ShutdownPlatformInterface() { + ImGui::DestroyViewportsRendererData(ImGui::GetCurrentContext()); ImGuiIO& io = ImGui::GetIO(); memset(&io.RendererInterface, 0, sizeof(io.RendererInterface)); } diff --git a/examples/imgui_impl_dx11.cpp b/examples/imgui_impl_dx11.cpp index b7c26cd..56fc7f6 100644 --- a/examples/imgui_impl_dx11.cpp +++ b/examples/imgui_impl_dx11.cpp @@ -619,6 +619,7 @@ void ImGui_ImplDX11_ShutdownPlatformInterface() { + ImGui::DestroyViewportsRendererData(ImGui::GetCurrentContext()); ImGuiIO& io = ImGui::GetIO(); memset(&io.RendererInterface, 0, sizeof(io.RendererInterface)); } diff --git a/examples/imgui_impl_dx12.cpp b/examples/imgui_impl_dx12.cpp index 7ed9a39..6de48c6 100644 --- a/examples/imgui_impl_dx12.cpp +++ b/examples/imgui_impl_dx12.cpp @@ -763,6 +763,7 @@ void ImGui_ImplDX12_ShutdownPlatformInterface() { + ImGui::DestroyViewportsRendererData(ImGui::GetCurrentContext()); ImGuiIO& io = ImGui::GetIO(); memset(&io.RendererInterface, 0, sizeof(io.RendererInterface)); } diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index d2a459d..91d363f 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -327,6 +327,7 @@ void ImGui_ImplOpenGL3_ShutdownPlatformInterface() { + ImGui::DestroyViewportsRendererData(ImGui::GetCurrentContext()); ImGuiIO& io = ImGui::GetIO(); memset(&io.RendererInterface, 0, sizeof(io.RendererInterface)); } diff --git a/examples/imgui_impl_dx10.cpp b/examples/imgui_impl_dx10.cpp index d88e2cc..014c4c3 100644 --- a/examples/imgui_impl_dx10.cpp +++ b/examples/imgui_impl_dx10.cpp @@ -611,6 +611,7 @@ void ImGui_ImplDX10_ShutdownPlatformInterface() { + ImGui::DestroyViewportsRendererData(ImGui::GetCurrentContext()); ImGuiIO& io = ImGui::GetIO(); memset(&io.RendererInterface, 0, sizeof(io.RendererInterface)); } diff --git a/examples/imgui_impl_dx11.cpp b/examples/imgui_impl_dx11.cpp index b7c26cd..56fc7f6 100644 --- a/examples/imgui_impl_dx11.cpp +++ b/examples/imgui_impl_dx11.cpp @@ -619,6 +619,7 @@ void ImGui_ImplDX11_ShutdownPlatformInterface() { + ImGui::DestroyViewportsRendererData(ImGui::GetCurrentContext()); ImGuiIO& io = ImGui::GetIO(); memset(&io.RendererInterface, 0, sizeof(io.RendererInterface)); } diff --git a/examples/imgui_impl_dx12.cpp b/examples/imgui_impl_dx12.cpp index 7ed9a39..6de48c6 100644 --- a/examples/imgui_impl_dx12.cpp +++ b/examples/imgui_impl_dx12.cpp @@ -763,6 +763,7 @@ void ImGui_ImplDX12_ShutdownPlatformInterface() { + ImGui::DestroyViewportsRendererData(ImGui::GetCurrentContext()); ImGuiIO& io = ImGui::GetIO(); memset(&io.RendererInterface, 0, sizeof(io.RendererInterface)); } diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index d2a459d..91d363f 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -327,6 +327,7 @@ void ImGui_ImplOpenGL3_ShutdownPlatformInterface() { + ImGui::DestroyViewportsRendererData(ImGui::GetCurrentContext()); ImGuiIO& io = ImGui::GetIO(); memset(&io.RendererInterface, 0, sizeof(io.RendererInterface)); } diff --git a/imgui.cpp b/imgui.cpp index 7ee87a3..f6e099c 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3909,6 +3909,20 @@ g.Initialized = true; } +void ImGui::DestroyViewportsPlaformData(ImGuiContext* context) +{ + if (context->IO.PlatformInterface.DestroyViewport) + for (int i = 0; i < context->Viewports.Size; i++) + context->IO.PlatformInterface.DestroyViewport(context->Viewports[i]); +} + +void ImGui::DestroyViewportsRendererData(ImGuiContext* context) +{ + if (context->IO.RendererInterface.DestroyViewport) + for (int i = 0; i < context->Viewports.Size; i++) + context->IO.RendererInterface.DestroyViewport(context->Viewports[i]); +} + // This function is merely here to free heap allocations. void ImGui::Shutdown(ImGuiContext* context) { @@ -3945,16 +3959,11 @@ g.OpenPopupStack.clear(); g.CurrentPopupStack.clear(); g.MouseViewport = g.MouseLastHoveredViewport = NULL; + DestroyViewportsPlaformData(context); + DestroyViewportsRendererData(context); for (int i = 0; i < g.Viewports.Size; i++) { ImGuiViewport* viewport = g.Viewports[i]; - if (!(viewport->Flags & ImGuiViewportFlags_MainViewport)) // FIXME-VIEWPORT - { - if (g.IO.RendererInterface.DestroyViewport) - g.IO.RendererInterface.DestroyViewport(viewport); - if (g.IO.PlatformInterface.DestroyViewport) - g.IO.PlatformInterface.DestroyViewport(viewport); - } viewport->PlatformUserData = viewport->PlatformHandle = viewport->RendererUserData = NULL; IM_DELETE(viewport); } diff --git a/examples/imgui_impl_dx10.cpp b/examples/imgui_impl_dx10.cpp index d88e2cc..014c4c3 100644 --- a/examples/imgui_impl_dx10.cpp +++ b/examples/imgui_impl_dx10.cpp @@ -611,6 +611,7 @@ void ImGui_ImplDX10_ShutdownPlatformInterface() { + ImGui::DestroyViewportsRendererData(ImGui::GetCurrentContext()); ImGuiIO& io = ImGui::GetIO(); memset(&io.RendererInterface, 0, sizeof(io.RendererInterface)); } diff --git a/examples/imgui_impl_dx11.cpp b/examples/imgui_impl_dx11.cpp index b7c26cd..56fc7f6 100644 --- a/examples/imgui_impl_dx11.cpp +++ b/examples/imgui_impl_dx11.cpp @@ -619,6 +619,7 @@ void ImGui_ImplDX11_ShutdownPlatformInterface() { + ImGui::DestroyViewportsRendererData(ImGui::GetCurrentContext()); ImGuiIO& io = ImGui::GetIO(); memset(&io.RendererInterface, 0, sizeof(io.RendererInterface)); } diff --git a/examples/imgui_impl_dx12.cpp b/examples/imgui_impl_dx12.cpp index 7ed9a39..6de48c6 100644 --- a/examples/imgui_impl_dx12.cpp +++ b/examples/imgui_impl_dx12.cpp @@ -763,6 +763,7 @@ void ImGui_ImplDX12_ShutdownPlatformInterface() { + ImGui::DestroyViewportsRendererData(ImGui::GetCurrentContext()); ImGuiIO& io = ImGui::GetIO(); memset(&io.RendererInterface, 0, sizeof(io.RendererInterface)); } diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index d2a459d..91d363f 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -327,6 +327,7 @@ void ImGui_ImplOpenGL3_ShutdownPlatformInterface() { + ImGui::DestroyViewportsRendererData(ImGui::GetCurrentContext()); ImGuiIO& io = ImGui::GetIO(); memset(&io.RendererInterface, 0, sizeof(io.RendererInterface)); } diff --git a/imgui.cpp b/imgui.cpp index 7ee87a3..f6e099c 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3909,6 +3909,20 @@ g.Initialized = true; } +void ImGui::DestroyViewportsPlaformData(ImGuiContext* context) +{ + if (context->IO.PlatformInterface.DestroyViewport) + for (int i = 0; i < context->Viewports.Size; i++) + context->IO.PlatformInterface.DestroyViewport(context->Viewports[i]); +} + +void ImGui::DestroyViewportsRendererData(ImGuiContext* context) +{ + if (context->IO.RendererInterface.DestroyViewport) + for (int i = 0; i < context->Viewports.Size; i++) + context->IO.RendererInterface.DestroyViewport(context->Viewports[i]); +} + // This function is merely here to free heap allocations. void ImGui::Shutdown(ImGuiContext* context) { @@ -3945,16 +3959,11 @@ g.OpenPopupStack.clear(); g.CurrentPopupStack.clear(); g.MouseViewport = g.MouseLastHoveredViewport = NULL; + DestroyViewportsPlaformData(context); + DestroyViewportsRendererData(context); for (int i = 0; i < g.Viewports.Size; i++) { ImGuiViewport* viewport = g.Viewports[i]; - if (!(viewport->Flags & ImGuiViewportFlags_MainViewport)) // FIXME-VIEWPORT - { - if (g.IO.RendererInterface.DestroyViewport) - g.IO.RendererInterface.DestroyViewport(viewport); - if (g.IO.PlatformInterface.DestroyViewport) - g.IO.PlatformInterface.DestroyViewport(viewport); - } viewport->PlatformUserData = viewport->PlatformHandle = viewport->RendererUserData = NULL; IM_DELETE(viewport); } diff --git a/imgui_internal.h b/imgui_internal.h index 7c297f6..cca7ff8 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1093,6 +1093,8 @@ IMGUI_API ImGuiViewport* FindViewportByPlatformHandle(void* platform_handle); IMGUI_API void SetNextWindowViewport(ImGuiID id); IMGUI_API void ShowViewportThumbnails(); + IMGUI_API void DestroyViewportsPlaformData(ImGuiContext* context); + IMGUI_API void DestroyViewportsRendererData(ImGuiContext* context); IMGUI_API void MarkIniSettingsDirty(); IMGUI_API ImGuiSettingsHandler* FindSettingsHandler(const char* type_name);