From 8de97d14d8f43e23d30a06aca15bbf3dad121374 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 10 Oct 2025 18:31:20 +0200 Subject: [PATCH] Backends: DX10, DX11: avoid ImGui_ImplXXXX_SwapBuffers() handlers for secondary viewports crashing if SwapChain could not be created. It's not really clear when that would fail but someone privately reported, and since we allow failure in ImGui_ImplDX11_CreateWindow() it makes sense to allow it here. --- backends/imgui_impl_dx10.cpp | 3 ++- backends/imgui_impl_dx11.cpp | 3 ++- docs/CHANGELOG.txt | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/backends/imgui_impl_dx10.cpp b/backends/imgui_impl_dx10.cpp index 376ed38b1..cff86fd0f 100644 --- a/backends/imgui_impl_dx10.cpp +++ b/backends/imgui_impl_dx10.cpp @@ -770,7 +770,8 @@ static void ImGui_ImplDX10_RenderViewport(ImGuiViewport* viewport, void*) static void ImGui_ImplDX10_SwapBuffers(ImGuiViewport* viewport, void*) { ImGui_ImplDX10_ViewportData* vd = (ImGui_ImplDX10_ViewportData*)viewport->RendererUserData; - vd->SwapChain->Present(0, 0); // Present without vsync + if (vd->SwapChain) + vd->SwapChain->Present(0, 0); // Present without vsync } void ImGui_ImplDX10_InitMultiViewportSupport() diff --git a/backends/imgui_impl_dx11.cpp b/backends/imgui_impl_dx11.cpp index 33751bfeb..d6b99a9f6 100644 --- a/backends/imgui_impl_dx11.cpp +++ b/backends/imgui_impl_dx11.cpp @@ -800,7 +800,8 @@ static void ImGui_ImplDX11_RenderWindow(ImGuiViewport* viewport, void*) static void ImGui_ImplDX11_SwapBuffers(ImGuiViewport* viewport, void*) { ImGui_ImplDX11_ViewportData* vd = (ImGui_ImplDX11_ViewportData*)viewport->RendererUserData; - vd->SwapChain->Present(0, 0); // Present without vsync + if (vd->SwapChain) + vd->SwapChain->Present(0, 0); // Present without vsync } static void ImGui_ImplDX11_InitMultiViewportSupport() diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 3cc0d2a1b..4a2a841e4 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -142,6 +142,8 @@ Docking+Viewports Branch: backends have been shutdown since 1.90.4. Changed into asserts. (#7175, #8945) - Backends: DX10, DX11, DX12: Disabled DXGI's Alt+Enter default behavior on secondary viewports managed by the backend. (#4350) [@PathogenDavid] +- Backends: DX10, DX11: avoid ImGui_ImplXXXX_SwapBuffers() handlers for secondary + viewports crashing if SwapChain could not be created. - Backends: Vulkan: Added a way to configure secondary viewport pipelinen creation by setting init_info.PipelineInfoForViewports fields. (#8946, #8110, #8111, #8686) - Backends: Vulkan: Added a way to configure secondary viewport swapchain VkImageUsageFlags