Skip to content

Commit aa9476a

Browse files
committed
IO: added ImGuiPlatformIO::ClearPlatformHandlers(), ClearRendererHandlers(). Backends: call those on Shutdown(). (ocornut#8945, ocornut#2769)
# Conflicts: # backends/imgui_impl_dx10.cpp # backends/imgui_impl_dx11.cpp # backends/imgui_impl_dx12.cpp # backends/imgui_impl_dx9.cpp # backends/imgui_impl_glfw.cpp # backends/imgui_impl_metal.mm # backends/imgui_impl_opengl2.cpp # backends/imgui_impl_opengl3.cpp # backends/imgui_impl_osx.mm # backends/imgui_impl_sdl2.cpp # backends/imgui_impl_sdl3.cpp # backends/imgui_impl_sdlgpu3.cpp # backends/imgui_impl_vulkan.cpp # backends/imgui_impl_win32.cpp # docs/CHANGELOG.txt # imgui.h
1 parent 3dd5165 commit aa9476a

21 files changed

+95
-1
lines changed

backends/imgui_impl_allegro5.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
// CHANGELOG
2424
// (minor and older changes stripped away, please see git history for details)
25+
// 2025-09-18: Call platform_io.ClearRendererHandlers() and platform_io.ClearPlatformHandlers() on shutdown.
2526
// 2025-08-12: Inputs: fixed missing support for ImGuiKey_PrintScreen under Windows, as raw Allegro 5 does not receive it.
2627
// 2025-08-12: Added ImGui_ImplAllegro5_SetDisplay() function to change current ALLEGRO_DISPLAY, as Allegro applications often need to do that.
2728
// 2025-07-07: Fixed texture update broken on some platforms where ALLEGRO_LOCK_WRITEONLY needed all texels to be rewritten.
@@ -500,6 +501,7 @@ void ImGui_ImplAllegro5_Shutdown()
500501
ImGui_ImplAllegro5_Data* bd = ImGui_ImplAllegro5_GetBackendData();
501502
IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?");
502503
ImGuiIO& io = ImGui::GetIO();
504+
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
503505

504506
ImGui_ImplAllegro5_InvalidateDeviceObjects();
505507
if (bd->VertexDecl)
@@ -510,6 +512,8 @@ void ImGui_ImplAllegro5_Shutdown()
510512
io.BackendPlatformName = io.BackendRendererName = nullptr;
511513
io.BackendPlatformUserData = nullptr;
512514
io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_RendererHasTextures);
515+
platform_io.ClearRendererHandlers();
516+
platform_io.ClearPlatformHandlers();
513517
IM_DELETE(bd);
514518
}
515519

backends/imgui_impl_dx10.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// CHANGELOG
1919
// (minor and older changes stripped away, please see git history for details)
2020
// 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
21+
// 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown.
2122
// 2025-06-11: DirectX10: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas.
2223
// 2025-05-07: DirectX10: Honor draw_data->FramebufferScale to allow for custom backends and experiment using it (consistently with other renderer backends, even though in normal condition it is not set under Windows).
2324
// 2025-01-06: DirectX10: Expose selected render state in ImGui_ImplDX10_RenderState, which you can access in 'void* platform_io.Renderer_RenderState' during draw callbacks.
@@ -639,14 +640,17 @@ void ImGui_ImplDX10_Shutdown()
639640
ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData();
640641
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
641642
ImGuiIO& io = ImGui::GetIO();
643+
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
642644

643645
ImGui_ImplDX10_ShutdownMultiViewportSupport();
644646
ImGui_ImplDX10_InvalidateDeviceObjects();
645647
if (bd->pFactory) { bd->pFactory->Release(); }
646648
if (bd->pd3dDevice) { bd->pd3dDevice->Release(); }
649+
647650
io.BackendRendererName = nullptr;
648651
io.BackendRendererUserData = nullptr;
649652
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures | ImGuiBackendFlags_RendererHasViewports);
653+
platform_io.ClearRendererHandlers();
650654
IM_DELETE(bd);
651655
}
652656

backends/imgui_impl_dx11.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
// CHANGELOG
2020
// (minor and older changes stripped away, please see git history for details)
2121
// 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
22+
// 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown.
2223
// 2025-06-11: DirectX11: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas.
2324
// 2025-05-07: DirectX11: Honor draw_data->FramebufferScale to allow for custom backends and experiment using it (consistently with other renderer backends, even though in normal condition it is not set under Windows).
2425
// 2025-02-24: [Docking] Added undocumented ImGui_ImplDX11_SetSwapChainDescs() to configure swap chain creation for secondary viewports.
@@ -660,15 +661,18 @@ void ImGui_ImplDX11_Shutdown()
660661
ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData();
661662
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
662663
ImGuiIO& io = ImGui::GetIO();
664+
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
663665

664666
ImGui_ImplDX11_ShutdownMultiViewportSupport();
665667
ImGui_ImplDX11_InvalidateDeviceObjects();
666668
if (bd->pFactory) { bd->pFactory->Release(); }
667669
if (bd->pd3dDevice) { bd->pd3dDevice->Release(); }
668670
if (bd->pd3dDeviceContext) { bd->pd3dDeviceContext->Release(); }
671+
669672
io.BackendRendererName = nullptr;
670673
io.BackendRendererUserData = nullptr;
671674
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures | ImGuiBackendFlags_RendererHasViewports);
675+
platform_io.ClearRendererHandlers();
672676
IM_DELETE(bd);
673677
}
674678

backends/imgui_impl_dx12.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
// CHANGELOG
2424
// (minor and older changes stripped away, please see git history for details)
2525
// 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
26+
// 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown.
2627
// 2025-06-19: Fixed build on MinGW. (#8702, #4594)
2728
// 2025-06-11: DirectX12: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas.
2829
// 2025-05-07: DirectX12: Honor draw_data->FramebufferScale to allow for custom backends and experiment using it (consistently with other renderer backends, even though in normal condition it is not set under Windows).
@@ -983,6 +984,7 @@ void ImGui_ImplDX12_Shutdown()
983984
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
984985
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
985986
ImGuiIO& io = ImGui::GetIO();
987+
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
986988

987989
// Manually delete main viewport render resources in-case we haven't initialized for viewports
988990
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
@@ -1002,6 +1004,7 @@ void ImGui_ImplDX12_Shutdown()
10021004
io.BackendRendererName = nullptr;
10031005
io.BackendRendererUserData = nullptr;
10041006
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures | ImGuiBackendFlags_RendererHasViewports);
1007+
platform_io.ClearRendererHandlers();
10051008
IM_DELETE(bd);
10061009
}
10071010

backends/imgui_impl_dx9.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
// CHANGELOG
2020
// (minor and older changes stripped away, please see git history for details)
2121
// 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
22+
// 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown.
2223
// 2025-06-11: DirectX9: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas.
2324
// 2024-10-07: DirectX9: Changed default texture sampler to Clamp instead of Repeat/Wrap.
2425
// 2024-02-12: DirectX9: Using RGBA format when supported by the driver to avoid CPU side conversion. (#6575)
@@ -367,13 +368,16 @@ void ImGui_ImplDX9_Shutdown()
367368
ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData();
368369
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
369370
ImGuiIO& io = ImGui::GetIO();
371+
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
370372

371373
ImGui_ImplDX9_ShutdownMultiViewportSupport();
372374
ImGui_ImplDX9_InvalidateDeviceObjects();
373375
if (bd->pd3dDevice) { bd->pd3dDevice->Release(); }
376+
374377
io.BackendRendererName = nullptr;
375378
io.BackendRendererUserData = nullptr;
376379
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures | ImGuiBackendFlags_RendererHasViewports);
380+
platform_io.ClearRendererHandlers();
377381
IM_DELETE(bd);
378382
}
379383

backends/imgui_impl_glfw.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
// CHANGELOG
3333
// (minor and older changes stripped away, please see git history for details)
3434
// 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
35+
// 2025-09-18: Call platform_io.ClearPlatformHandlers() on shutdown.
3536
// 2025-09-15: Content Scales are always reported as 1.0 on Wayland. FramebufferScale are always reported as 1.0 on X11. (#8920, #8921)
3637
// 2025-09-10: [Docking] Improve multi-viewport behavior in tiling WMs on X11 via the ImGui_ImplGlfw_SetWindowFloating() function. Note: using GLFW backend on Linux/BSD etc. requires linking with -lX11. (#8884, #8474, #8289)
3738
// 2025-07-08: Made ImGui_ImplGlfw_GetContentScaleForWindow(), ImGui_ImplGlfw_GetContentScaleForMonitor() helpers return 1.0f on Emscripten and Android platforms, matching macOS logic. (#8742, #8733)
@@ -816,7 +817,9 @@ void ImGui_ImplGlfw_Shutdown()
816817
{
817818
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
818819
IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?");
820+
819821
ImGuiIO& io = ImGui::GetIO();
822+
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
820823

821824
ImGui_ImplGlfw_ShutdownMultiViewportSupport();
822825

@@ -841,6 +844,7 @@ void ImGui_ImplGlfw_Shutdown()
841844
io.BackendPlatformName = nullptr;
842845
io.BackendPlatformUserData = nullptr;
843846
io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad | ImGuiBackendFlags_PlatformHasViewports | ImGuiBackendFlags_HasMouseHoveredViewport);
847+
platform_io.ClearPlatformHandlers();
844848
ImGui_ImplGlfw_ContextMap_Remove(bd->Window);
845849
IM_DELETE(bd);
846850
}

backends/imgui_impl_metal.mm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// CHANGELOG
1919
// (minor and older changes stripped away, please see git history for details)
2020
// 2025-XX-XX: Metal: Added support for multiple windows via the ImGuiPlatformIO interface.
21+
// 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown.
2122
// 2025-06-11: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas. Removed ImGui_ImplMetal_CreateFontsTexture() and ImGui_ImplMetal_DestroyFontsTexture().
2223
// 2025-02-03: Metal: Crash fix. (#8367)
2324
// 2025-01-08: Metal: Fixed memory leaks when using metal-cpp (#8276, #8166) or when using multiple contexts (#7419).
@@ -159,14 +160,17 @@ void ImGui_ImplMetal_Shutdown()
159160
ImGui_ImplMetal_Data* bd = ImGui_ImplMetal_GetBackendData();
160161
IM_UNUSED(bd);
161162
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
163+
ImGuiIO& io = ImGui::GetIO();
164+
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
165+
162166
ImGui_ImplMetal_ShutdownMultiViewportSupport();
163167
ImGui_ImplMetal_DestroyDeviceObjects();
164168
ImGui_ImplMetal_DestroyBackendData();
165169

166-
ImGuiIO& io = ImGui::GetIO();
167170
io.BackendRendererName = nullptr;
168171
io.BackendRendererUserData = nullptr;
169172
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures | ImGuiBackendFlags_RendererHasViewports);
173+
platform_io.ClearRendererHandlers();
170174
}
171175

172176
void ImGui_ImplMetal_NewFrame(MTLRenderPassDescriptor* renderPassDescriptor)

backends/imgui_impl_opengl2.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
// CHANGELOG
2828
// (minor and older changes stripped away, please see git history for details)
2929
// 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
30+
// 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown.
3031
// 2025-07-15: OpenGL: Set GL_UNPACK_ALIGNMENT to 1 before updating textures. (#8802)
3132
// 2025-06-11: OpenGL: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas. Removed ImGui_ImplOpenGL2_CreateFontsTexture() and ImGui_ImplOpenGL2_DestroyFontsTexture().
3233
// 2024-10-07: OpenGL: Changed default texture sampler to Clamp instead of Repeat/Wrap.
@@ -124,12 +125,15 @@ void ImGui_ImplOpenGL2_Shutdown()
124125
ImGui_ImplOpenGL2_Data* bd = ImGui_ImplOpenGL2_GetBackendData();
125126
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
126127
ImGuiIO& io = ImGui::GetIO();
128+
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
127129

128130
ImGui_ImplOpenGL2_ShutdownMultiViewportSupport();
129131
ImGui_ImplOpenGL2_DestroyDeviceObjects();
132+
130133
io.BackendRendererName = nullptr;
131134
io.BackendRendererUserData = nullptr;
132135
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasTextures | ImGuiBackendFlags_RendererHasViewports);
136+
platform_io.ClearRendererHandlers();
133137
IM_DELETE(bd);
134138
}
135139

backends/imgui_impl_opengl3.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
// CHANGELOG
2626
// (minor and older changes stripped away, please see git history for details)
2727
// 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
28+
// 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown.
2829
// 2025-07-22: OpenGL: Add and call embedded loader shutdown during ImGui_ImplOpenGL3_Shutdown() to facilitate multiple init/shutdown cycles in same process. (#8792)
2930
// 2025-07-15: OpenGL: Set GL_UNPACK_ALIGNMENT to 1 before updating textures (#8802) + restore non-WebGL/ES update path that doesn't require a CPU-side copy.
3031
// 2025-06-11: OpenGL: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas. Removed ImGui_ImplOpenGL3_CreateFontsTexture() and ImGui_ImplOpenGL3_DestroyFontsTexture().
@@ -430,12 +431,15 @@ void ImGui_ImplOpenGL3_Shutdown()
430431
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
431432
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
432433
ImGuiIO& io = ImGui::GetIO();
434+
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
433435

434436
ImGui_ImplOpenGL3_ShutdownMultiViewportSupport();
435437
ImGui_ImplOpenGL3_DestroyDeviceObjects();
438+
436439
io.BackendRendererName = nullptr;
437440
io.BackendRendererUserData = nullptr;
438441
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures | ImGuiBackendFlags_RendererHasViewports);
442+
platform_io.ClearRendererHandlers();
439443
IM_DELETE(bd);
440444

441445
#ifdef IMGUI_IMPL_OPENGL_LOADER_IMGL3W

backends/imgui_impl_osx.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
// CHANGELOG
3535
// (minor and older changes stripped away, please see git history for details)
3636
// 2025-XX-XX: Added support for multiple windows via the ImGuiPlatformIO interface.
37+
// 2025-09-18: Call platform_io.ClearPlatformHandlers() on shutdown.
3738
// 2025-07-08: [Docking] Fixed multi-viewport handling broken on 2025-06-02. (#8644, #8777)
3839
// 2025-06-27: Added ImGuiMouseCursor_Wait and ImGuiMouseCursor_Progress mouse cursor support.
3940
// 2025-06-12: ImGui_ImplOSX_HandleEvent() only process event for window containing our view. (#8644)
@@ -550,9 +551,12 @@ void ImGui_ImplOSX_Shutdown()
550551
ImGui_ImplOSX_ShutdownMultiViewportSupport();
551552
ImGui_ImplOSX_DestroyBackendData();
552553
ImGuiIO& io = ImGui::GetIO();
554+
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
555+
553556
io.BackendPlatformName = nullptr;
554557
io.BackendPlatformUserData = nullptr;
555558
io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasGamepad | ImGuiBackendFlags_PlatformHasViewports);
559+
platform_io.ClearPlatformHandlers();
556560
}
557561

558562
static void ImGui_ImplOSX_UpdateMouseCursor()

0 commit comments

Comments
 (0)