ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
60.63k stars 10.24k forks source link

Crash on Ctrl+Tab for DockSpaceOverViewport with PassthruCentralNode flag #4792

Closed ilovexyz closed 1 year ago

ilovexyz commented 2 years ago

Version/Branch of Dear ImGui:

Version: 1.86 WIP (18516) Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp Compiler: MSVC Operating System: Windows 10

My Issue/Question:

I want to use the ImGui::DockSpaceOverViewport function in my application, but it will cause crash when pressing Ctrl+Tab navigation key, i wonder if this is a bug or i didn't understand the usage of dockspace.

Screenshots/Video

Step to reproduce the issue based on the example_glfw_opengl3:

exception

Code crashes here:

exception

Standalone, minimal, complete and verifiable example:

Just add the following code to the main.cpp of example_glfw_opengl3 will reproduce the issue.

// show dock
ImGui::DockSpaceOverViewport(ImGui::GetMainViewport(), ImGuiDockNodeFlags_PassthruCentralNode);
code
ocornut commented 2 years ago

This is code we changed recently. Can you confirm if updating to very latest commit still reproduce the issue?

ilovexyz commented 2 years ago

yes, i just pull the lastest docking branch, the above issue is running using the lastest code

ilovexyz commented 2 years ago

This is code we changed recently. Can you confirm if updating to very latest commit still reproduce the issue?

if add the following code before accessing CmdBuffer.Data, it will crash elsewhere.

    if (CmdBuffer.Size == 0)
        return;

from the debug stack, i can see the value of CmdBuffer.Size is zero, but i don't know how to correct this.

ocornut commented 2 years ago

Should be fixed by 0647cf4, thank you very much for reporting and helping!

ilovexyz commented 2 years ago

wow, thank you for the quick response, i just pulled and checked, no crash any more!

RT2Code commented 2 years ago

I stumbled upon the same issue while migrating to imgui 1.87 wip (docking branch). It seems to happens only with empty windows. You can reproduce it like this :

const ImGuiID dock_id = ImGui::DockSpaceOverViewport(ImGui::GetMainViewport());
ImGui::SetNextWindowDockID(dock_id, ImGuiCond_FirstUseEver);
ImGui::Begin("Window");
ImGui::End();

A Begin followed by and End call will always result in a crash if the window is docked and reached with ctrl+tab. This can also be reproduced with the log or long text display windows of the imgui demos because theses windows have such a code path.

ocornut commented 2 years ago

Thank you, will look into fixing soon.

ocornut commented 2 years ago

@RT222 I cannot reproduce a crash. Can you post details and a callstack? What is your backend and your config flags? (best to Copy the build info available in About box).

I however noticed that during CTRL+Tabbing the background color of the viewport will start appearing above non-docked windows which is most likely due to the BgColor/dimming changes done in 1.86.

RT2Code commented 2 years ago

Using the latest docking commit (https://github.com/ocornut/imgui/commit/08f3aa89723f8e41a8b10aa0c60c6617da563e18) and the default imgui examples files without any modification, I was able to reproduce this crash consistently on all win32 and sdl2 based backends by docking the log window on the main viewport.

Then I tried to test more build configurations and I think I found why you couldn't reproduce it on your end : it only happens on 64 bits builds. Try it with any backend built on debug/64bits, and I'm pretty confident you should get this crash too.

Here's my build infos :

Dear ImGui 1.87 WIP (18612)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: _WIN32
define: _WIN64
define: _MSC_VER=1930
define: _MSVC_LANG=201402
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_win32
io.BackendRendererName: imgui_impl_dx11
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: 1 fonts, Flags: 0x00000000, TexSize: 512,64
io.DisplaySize: 1264.00,761.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
ocornut commented 2 years ago

Thank you I have managed to repro. It is possible to get a better assert with #define IMGUI_DEBUG_PARANOID in imconfig.h

Pushed a fix f1a0731 It's embarrassing how many regressions those window dimming/bgcolor system changes caused :(

Leaving this open because of : > I however noticed that during CTRL+Tabbing the background color of the viewport will start appearing above non-docked windows which is most likely due to the BgColor/dimming changes done in 1.86.

RT2Code commented 2 years ago

Everything is working fine now, thanks for the quick fix.

ocornut commented 1 year ago

Leaving this open because of : I however noticed that during CTRL+Tabbing the background color of the viewport will start appearing above non-docked windows which is most likely due to the BgColor/dimming changes done in 1.86.

Moving this to #5917 as main issue here has been fixed a while ago.