imgui icon indicating copy to clipboard operation
imgui copied to clipboard

Win32 + D3D12 docking branch crash following dragging a panel outside of render window and fully back inside again.

Open EmilFransson opened this issue 2 years ago • 9 comments
trafficstars

Version/Branch of Dear ImGui:

Version: 1.89 WIP (18804) Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_win32.cpp + imgui_impl_dx12.cpp Operating System: Windows 11 CPU: 12th Gen Intel(R) Core(TM) i7-12700H 2.70 GHz GPU: NVidia RTX 3070ti Mobile Drivers: As of now the latest (528.24)

Extended information:

Dear ImGui 1.89 WIP (18804)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: _WIN32
define: _WIN64
define: _MSC_VER=1932
define: _MSVC_LANG=201402
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_win32
io.BackendRendererName: imgui_impl_dx12
io.ConfigFlags: 0x00000441
 NavEnableKeyboard
 DockingEnable
 ViewportsEnable
io.ConfigViewportsNoDecoration
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x00001C0E
 HasMouseCursors
 HasSetMousePos
 PlatformHasViewports
 HasMouseHoveredViewport
 RendererHasVtxOffset
 RendererHasViewports
--------------------------------
io.Fonts: 3 fonts, Flags: 0x00000000, TexSize: 512,512
io.DisplaySize: 1280.00,720.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

My Issue/Question: I am crashing both in my personal project, using ImGUI docking branch version 1.89 WIP (18804) as well as on the newest official docking branch example, ver 1.89.3 WIP (18923), using windows and d3d12 as backend, following the very same operation. This operation is displayed for both projects in the Screenshots/Video section along with the crash and is as follows: I grab an imgui panel, move it outside the render window (which triggers a small stutter), followed by moving it FULLY back inside the render window and release the panel. This triggers a crash, usually on Present or on the line of code following the Present-call. The error message is as such:

Exception thrown at 0x00007FFE1D4D7958 (nvwgf2umx.dll) in example_win32_directx12.exe: 0xC0000005: Access violation reading location 0x0000023622BA0250.

Here is an explanation I found on the dll-file (NOT verified):

Nvwgf2umx. dll file, also known as NVIDIA D3D10 Driver, Version 340.43, is commonly associated with NVIDIA D3D10 drivers. It is an essential component, which ensures that Windows programs operate properly. - wikidll.com

This error has been reproduced on three different computers, however on my desktop, featuring a 1080ti on a windows 10 system, everything works like a charm without any errors at all.

Note that this crash occurs for both Debug & Release configuration.

Screenshots/Video Personal project crash example: https://gyazo.com/9d9b517b71666852289940670c17bbf8 Official latest ImGUI win32_dx12 docking branch crash example: https://gyazo.com/de2aa54ac64178c49da0d79c1cd84a8b

Standalone, minimal, complete and verifiable example: Refer to the official newest docking branch example for win32 + Dx12 for a verifiable example.

EmilFransson avatar Jan 27 '23 12:01 EmilFransson

MAJOR UPDATE: I just recently decided to update the NVidia drivers on my desktop, the only system where I had no crash. I went from driver version 522.06 -> 528.24, the same GPU driver version as my laptop. Now it crashes on my desktop system too, meaning I now have no system that can correctly perform the imgui panel operation. This makes it 4 systems where this crash occurs and I am considering calling this a "global issue", rather than something just on my end.

It crashes on Present(), just like on the other systems, with the very same error message.

EmilFransson avatar Jan 28 '23 12:01 EmilFransson

Just want to leave a quick bnote to @ocornut here, since my issue seems similair. Docking branch, Mac M1, SDL2 + OpenGL Renderer, HDPI, ViewPort enabled... It is impossible to grag a panel out of the bounds of the main window - there are crashes, visual glitches, and other UB. The same code works perfectly with other renderers as well as it does on master branch. As a workaround I removed io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; from my initialization code and now dragging works fine. But it would be nice to have viewport facilities enabled, of couese :)

Papirosnik avatar Jan 31 '23 01:01 Papirosnik

@EmilFransson I have updated my NVIDIA drivers to 528.24 and unfortunately not seeing the problem here :( Lacking a repro on my side, we would likely need you to investigate this on your end, see how DX12 can be debugged and potentially drivers, or further toy with DX12 API calls (I'm myself not sure).

@Papirosnik This needs its own issue, you need to specify version, if there are crashes provide calls-tack, videos of glitches etc.

ocornut avatar Jan 31 '23 18:01 ocornut

Someone came to me with a same issue, seemingly caused by the same drivers update, and they suggested not calling SafeRelease(vd->FrameCtx[i].RenderTarget); made the crash disappear, tho I imagine that would cause a leak and be reported in the debug layer, this may be a hint as to where the issue is.

ocornut avatar Feb 03 '23 13:02 ocornut

@EmilFransson Can you share a minidump (with memory if possible) when you reproduce this on your system?

sherief avatar Feb 10 '23 12:02 sherief

I was able to repro this issue using the example_win32_directx12 project. After updating to NVIDIA Driver 531.41 the issue appears to have been fixed.

Using: GPU: RTX 3070ti IMGUI: v1.89.5 WIP

RichardLions avatar Mar 23 '23 18:03 RichardLions

EDIT: looking closer, realise probably mixing up an unrelated bug with this one* Win10, v1.89.5 WIP, RTX 3060, Driver 531.41

Hitting this but only reproduces when using full screen (i.e. alt+enter), in a debug build.

Dragging it outside seems to trigger a WM_SIZE (i.e. resize), which causes a resize of buffers causing the exception (continuing past it seems to cause no immediate side-effects). Doesn't happen in a release build (no debug layer).

D3D12 ERROR: ID3D12Resource2::<final-release>: CORRUPTION: An ID3D12Resource object (0x000001F8EA970390:'Unnamed Object') is referenced by GPU operations in-flight on Command Queue (0x000001F8E3F8EFE0:'Unnamed ID3D12CommandQueue Object').  It is not safe to final-release objects that may have GPU operations pending.  This can result in application instability. [ EXECUTION ERROR #921: OBJECT_DELETED_WHILE_STILL_IN_USE]
D3D12: **BREAK** enabled for the previous message, which was: [ ERROR EXECUTION #921: OBJECT_DELETED_WHILE_STILL_IN_USE ]

Have also managed to reproduce this by alt-tabbing whilst full screen.


Changing the resize to a deferred resize after the message pump seems to avoid the above issues. i.e. cache the change size details, and do the actual resize after the PeekMessage/TranslateMessage/DispatchMessage. Seems to stops it possibly destroying and re-creating it several times in quick succession.

struct DeferredResize 
{
    bool Pending = false;
    UINT X = 0;
    UINT Y = 0;
};
static DeferredResize               g_deferredResize = {};
// ...
        ::DispatchMessage(&msg);
            if (msg.message == WM_QUIT)
                done = true;
        }
        if (done)
            break;

        if (g_deferredResize.Pending) 
        {
            CleanupRenderTarget();
            HRESULT result = g_pSwapChain->ResizeBuffers(0, g_deferredResize.X, g_deferredResize.Y, DXGI_FORMAT_UNKNOWN, DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT);
            assert(SUCCEEDED(result) && "Failed to resize swapchain.");
            CreateRenderTarget();

            g_deferredResize.Pending = false;
        }
// ...
case WM_SIZE:
        if (wParam != SIZE_MINIMIZED)
        {
            g_deferredResize.X = (UINT)LOWORD(lParam);
            g_deferredResize.Y = (UINT)HIWORD(lParam);
            g_deferredResize.Pending = true;
        }
        else
        {
            g_deferredResize.Pending = false;
        }
        return 0;

StewMcc avatar Apr 03 '23 09:04 StewMcc

Just found today that the size update of the platform windows is one frame delay. I wonder if it is related to this issue. https://github.com/ocornut/imgui/issues/7152

devkaiwang avatar Dec 19 '23 19:12 devkaiwang

I have a similar issue with SDL + OpenGL where the rendering stops completely and input events aren't received anymore once I drag a window outside of the application window that ImGui renders in.

broken-bytes avatar Mar 01 '24 21:03 broken-bytes