Backends: DX11: crash in ImGui_ImplDX11_RenderWindow when a viewport's RTView is null (device removal on undock) #9546

Closed
opened 2026-09-16 12:58:14 +00:00 by lailoken · 0 comments
lailoken commented 2026-09-16 12:58:14 +00:00 (Migrated from github.com)

Version/Branch of Dear ImGui:

Version 1.93.0 WIP (19292), Branch: docking

Back-ends:

imgui_impl_win32.cpp + imgui_impl_dx11.cpp

Compiler, OS:

ndows 11 (build 26200) + MSVC 2022 (19.50), NVIDIA RTX 2000 Ada laptop GPU, 5 external 4K monitors at 150% DPI via a dock

Full config/build information:

N/A

Details:

Crash in mGui_ImplDX11_RenderWindow when a secondary viewport's render target view is null. Reproduced once in production when a laptop was undocked while several viewport windows were open on the dock's monitors; the crash landed during the display topology change (the app still enumerated all 5 monitors at crash time).

The user cannot recall the exact conditions, and I've not been able to reproduce, but I suspect the cause.

Release-build callstack (system frames resolved to nearest export only):

 0. d3d11.dll (nearest export D3DKMTOpenResource)
 1. ImGui_ImplDX11_RenderWindow
 2. ImGui::RenderPlatformWindowsDefault
 3. <app main loop>

ImGui_ImplDX11_RenderWindow makes two direct D3D calls, OMSetRenderTargets(1, &vd->RTView, nullptr) and ClearRenderTargetView(vd->RTView, ...). vd->RTView stays null when ImGui_ImplDX11_SetWindowSize returns early after ResizeBuffers/GetBuffer fail (it prints "failed creating buffers"), and when CreateSwapChain fails in ImGui_ImplDX11_CreateWindow (the IM_ASSERT is compiled out in release). ClearRenderTargetView(nullptr) faults inside the runtime without the debug layer. Losing all displays on a discrete laptop GPU during undock is a known DXGI_ERROR_DEVICE_REMOVED trigger, which fits.

Proposed fix, two lines at the top of ImGui_ImplDX11_RenderWindow after vd is fetched:

 if (vd->RTView == nullptr) // Swap chain creation or resize failed (e.g. device removed)
     return;

The viewport stays blank until a later SetWindowSize succeeds, rather than crashing the application.

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

A faithful repro needs a device loss, which was hard to script.

### Version/Branch of Dear ImGui: Version 1.93.0 WIP (19292), Branch: docking ### Back-ends: imgui_impl_win32.cpp + imgui_impl_dx11.cpp ### Compiler, OS: ndows 11 (build 26200) + MSVC 2022 (19.50), NVIDIA RTX 2000 Ada laptop GPU, 5 external 4K monitors at 150% DPI via a dock ### Full config/build information: N/A ### Details: Crash in `mGui_ImplDX11_RenderWindow` when a secondary viewport's render target view is `null`. Reproduced once in production when a laptop was undocked while several viewport windows were open on the dock's monitors; the crash landed during the display topology change (the app still enumerated all 5 monitors at crash time). The user cannot recall the exact conditions, and I've not been able to reproduce, but I suspect the cause. Release-build callstack (system frames resolved to nearest export only): ``` 0. d3d11.dll (nearest export D3DKMTOpenResource) 1. ImGui_ImplDX11_RenderWindow 2. ImGui::RenderPlatformWindowsDefault 3. <app main loop> ``` `ImGui_ImplDX11_RenderWindow` makes two direct D3D calls, `OMSetRenderTargets(1, &vd->RTView, nullptr)` and `ClearRenderTargetView(vd->RTView, ...)`. `vd->RTView` stays null when `ImGui_ImplDX11_SetWindowSize` returns early after `ResizeBuffers/GetBuffer` fail (it prints "failed creating buffers"), and when `CreateSwapChain` fails in `ImGui_ImplDX11_CreateWindow` (the `IM_ASSERT` is compiled out in release). `ClearRenderTargetView(nullptr)` faults inside the runtime without the debug layer. Losing all displays on a discrete laptop GPU during undock is a known `DXGI_ERROR_DEVICE_REMOVED` trigger, which fits. Proposed fix, two lines at the top of `ImGui_ImplDX11_RenderWindow` after `vd` is fetched: ``` if (vd->RTView == nullptr) // Swap chain creation or resize failed (e.g. device removed) return; ``` The viewport stays blank until a later `SetWindowSize` succeeds, rather than crashing the application. ### Screenshots/Video: _No response_ ### Minimal, Complete and Verifiable Example code: A faithful repro needs a device loss, which was hard to script.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#9546
No description provided.