Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nav crashes When Alt Clicking The Main GLFW Window #2609

Closed
mastergog1 opened this issue Jun 4, 2019 · 4 comments
Closed

Nav crashes When Alt Clicking The Main GLFW Window #2609

mastergog1 opened this issue Jun 4, 2019 · 4 comments
Labels
bug nav keyboard/gamepad navigation

Comments

@mastergog1
Copy link

Version: Latest
Branch: docking

Back-ends: imgui_impl_GLFWcpp + imgui_impl_OPENGL.cpp
Operating System: Windows 10

The example app crashes when you interact in any way with an IMGUI window outside of the GLFW window, and then follow that interaction with an ALT + LEFT MOUSE CLICK on the GLFW window. Just move the demo window next to the glfw window, click the demo window anywhere, then alt click the glfw window.

I'm also using this branch for a work project and the same crash is happening there.

Call Stack:
->ImGui::NewFrame();
->NavUpdate()
->SetNavID(unsigned int id, int nav_layer)
-> g.NavWindow->NavLastIds[nav_layer] = id;

g.NavWindow seems to be NULL.

Same crash happens on both OpenGL examples but doesn't happen on the DirectX examples.

@mastergog1 mastergog1 changed the title OpenGl Example Scene Crashes When OpenGl Example Scene Crashes When Alt Clicking The Main GLFW Window Jun 4, 2019
@ocornut ocornut added bug nav keyboard/gamepad navigation backends labels Jun 4, 2019
ocornut added a commit that referenced this issue Jun 4, 2019
…ndow with a menu at the same frame as clearing the focus. This was in most noticeable in some back-ends with emits key release events when focusing another viewport. (#2609)
@ocornut
Copy link
Owner

ocornut commented Jun 4, 2019

Very interesting bug. It only happens when the first window has a menu bar and with the GLFW/SDL back-ends because:

  • Pressing Alt sets up to toggle to the menu on release
  • Clicking another viewport has GLFW/SDL sent an Alt key released events to the previously viewport (something which the Win32 back-ends doesn't.)
  • Which in returns switches us to the menu layer and request the nav system to find an initial item to focus on. By the time the result arrives on the next frame, clicking on void has cleared focused.

Now fixed! Thanks for the bug report!

@ocornut ocornut closed this as completed Jun 4, 2019
@magicfoo
Copy link

magicfoo commented Jul 9, 2020

I just got a similar crash in a different context.
version: latest at this date
back-end: proprietary game engine dx11

g.NavWindow == NULL

in window->DC.NavLayerActiveMaskNext |= window->DC.NavLayerCurrentMask;
if (g.NavId == id || g.NavAnyRequest)
if (g.NavWindow->RootWindowForNav == window->RootWindowForNav)
if (window == g.NavWindow || ((window->Flags | g.NavWindow->Flags) & ImGuiWindowFlags_NavFlattened))
NavProcessItem(window, nav_bb_arg ? *nav_bb_arg : bb, id);

call stack:

  • ImGui::ItemAdd() Line 6908
  • ImGui::CollapseButton() Line 798
  • ImGui::RenderWindowTitleBarContents() Line 5314
  • ImGui::Begin("Debug##Default")
  • ImGui::NewFrame()

I was hiding the unique window with a KB shortcut (i.e. it didnt enter the ImGui::Begin() of my dialog but crashes on the dummy one apparently).

@ocornut ocornut reopened this Jul 14, 2020
@ocornut ocornut removed the backends label Feb 22, 2021
@ocornut ocornut changed the title OpenGl Example Scene Crashes When Alt Clicking The Main GLFW Window Nav crashes When Alt Clicking The Main GLFW Window Mar 15, 2021
@ocornut
Copy link
Owner

ocornut commented Sep 10, 2021

@magicfoo Do you remember exactly how to repro this?

I'm trying to track all code paths but haven't found a possible crash yet. (But code has changed yet, and there are asserts early on, nowadays I guess you are more likely to assert in NavUpdateAnyRequestFlag().

If this happen to you or anyone could you tell me the values of

  • g.NavId
  • g.NavAnyRequest
  • g.NavInitRequest
  • g.NavMoveScoringItems

Thanks!

@ocornut
Copy link
Owner

ocornut commented Sep 10, 2021

Found the bug!

I checked out July 10, 2020 version (~1.77) and went through every code paths and possible flow I could find.

  • July 10 2020 code already had this assert already. Knowing this is really helpful.
  • The only path that can set g.NavAnyRequest to true verify that g.NavWindow != NULL.
  • All paths setting g.NavId != 0 are doing it where g.NavWindow != NULL (verified this several times)
  • All paths which can set g.NavWindow = NULL are doing it while g.NavId != 0 (verified this several times)
  • Therefore I found that if that there are paths setting g.NavWindow = NULL while there's an ongoing request and NavAnyRequest is not updated.
  • Calling FocusWindow(NULL) mid-frame while there is a nav request ongoing causes the crash.

Researched this further and realized this was fixed already by 25679a4 (March 2021)
Closing!

@ocornut ocornut closed this as completed Sep 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug nav keyboard/gamepad navigation
Projects
None yet
Development

No branches or pull requests

3 participants