Viewport: Give a chance to platform and renderer to actually destroy their data. Otherwise the regular ImplXXX_Shutdown + following by DestroyContext() order fails to fullifl this. (#1542)

This commit is contained in:
omar 2018-03-03 22:53:31 +01:00
parent cab41d954e
commit e026c8d3b7
6 changed files with 22 additions and 7 deletions

View File

@ -611,6 +611,7 @@ void ImGui_ImplDX10_InitPlatformInterface()
void ImGui_ImplDX10_ShutdownPlatformInterface() void ImGui_ImplDX10_ShutdownPlatformInterface()
{ {
ImGui::DestroyViewportsRendererData(ImGui::GetCurrentContext());
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
memset(&io.RendererInterface, 0, sizeof(io.RendererInterface)); memset(&io.RendererInterface, 0, sizeof(io.RendererInterface));
} }

View File

@ -619,6 +619,7 @@ void ImGui_ImplDX11_InitPlatformInterface()
void ImGui_ImplDX11_ShutdownPlatformInterface() void ImGui_ImplDX11_ShutdownPlatformInterface()
{ {
ImGui::DestroyViewportsRendererData(ImGui::GetCurrentContext());
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
memset(&io.RendererInterface, 0, sizeof(io.RendererInterface)); memset(&io.RendererInterface, 0, sizeof(io.RendererInterface));
} }

View File

@ -763,6 +763,7 @@ void ImGui_ImplDX12_InitPlatformInterface()
void ImGui_ImplDX12_ShutdownPlatformInterface() void ImGui_ImplDX12_ShutdownPlatformInterface()
{ {
ImGui::DestroyViewportsRendererData(ImGui::GetCurrentContext());
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
memset(&io.RendererInterface, 0, sizeof(io.RendererInterface)); memset(&io.RendererInterface, 0, sizeof(io.RendererInterface));
} }

View File

@ -327,6 +327,7 @@ void ImGui_ImplOpenGL3_InitPlatformInterface()
void ImGui_ImplOpenGL3_ShutdownPlatformInterface() void ImGui_ImplOpenGL3_ShutdownPlatformInterface()
{ {
ImGui::DestroyViewportsRendererData(ImGui::GetCurrentContext());
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
memset(&io.RendererInterface, 0, sizeof(io.RendererInterface)); memset(&io.RendererInterface, 0, sizeof(io.RendererInterface));
} }

View File

@ -3909,6 +3909,20 @@ void ImGui::Initialize(ImGuiContext* context)
g.Initialized = true; 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. // This function is merely here to free heap allocations.
void ImGui::Shutdown(ImGuiContext* context) void ImGui::Shutdown(ImGuiContext* context)
{ {
@ -3945,16 +3959,11 @@ void ImGui::Shutdown(ImGuiContext* context)
g.OpenPopupStack.clear(); g.OpenPopupStack.clear();
g.CurrentPopupStack.clear(); g.CurrentPopupStack.clear();
g.MouseViewport = g.MouseLastHoveredViewport = NULL; g.MouseViewport = g.MouseLastHoveredViewport = NULL;
DestroyViewportsPlaformData(context);
DestroyViewportsRendererData(context);
for (int i = 0; i < g.Viewports.Size; i++) for (int i = 0; i < g.Viewports.Size; i++)
{ {
ImGuiViewport* viewport = g.Viewports[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; viewport->PlatformUserData = viewport->PlatformHandle = viewport->RendererUserData = NULL;
IM_DELETE(viewport); IM_DELETE(viewport);
} }

View File

@ -1093,6 +1093,8 @@ namespace ImGui
IMGUI_API ImGuiViewport* FindViewportByPlatformHandle(void* platform_handle); IMGUI_API ImGuiViewport* FindViewportByPlatformHandle(void* platform_handle);
IMGUI_API void SetNextWindowViewport(ImGuiID id); IMGUI_API void SetNextWindowViewport(ImGuiID id);
IMGUI_API void ShowViewportThumbnails(); IMGUI_API void ShowViewportThumbnails();
IMGUI_API void DestroyViewportsPlaformData(ImGuiContext* context);
IMGUI_API void DestroyViewportsRendererData(ImGuiContext* context);
IMGUI_API void MarkIniSettingsDirty(); IMGUI_API void MarkIniSettingsDirty();
IMGUI_API ImGuiSettingsHandler* FindSettingsHandler(const char* type_name); IMGUI_API ImGuiSettingsHandler* FindSettingsHandler(const char* type_name);