pkdawson / imgui-godot

Dear ImGui plugin for Godot 4
MIT License
318 stars 18 forks source link

ImGui Viewports: Main window stops responding to input #23

Closed pkdawson closed 1 year ago

pkdawson commented 1 year ago

If a window is created as the mouse leaves the frame of the main window, and the “mouse button up” event isn’t received, then the main window will stop responding to all inputs.

Workaround

Drag the new window back into the main window. You may need to repeat this once or twice (drag it out, then back in).

Notes

This bug is easy to reproduce (depending on the input handling code), but it’s been frustratingly difficult to find the root cause, so I’m documenting it here.

All I know is that in this situation, the main window stops receiving window messages at all, and it’s not caused by WS_EX_NOACTIVATE or MA_NOACTIVATEANDEAT. Destroying the new window usually fixes it, at least temporarily.

I’ve been unable to make an MRP. I’m not entirely convinced it’s a Godot bug, but I also don’t know how my code or ImGui could break the main window like that.

TODO: Examine the following scenario

Reproduce the issue, then ctrl+tab to a window within the main window. This fixes the main window. Then click the new window, which breaks it again. This can be repeated. Ctrl+tab to the new window does not break it.

pkdawson commented 1 year ago

Finally found the problem!

https://github.com/godotengine/godot/blob/db8c85a75ff0a52eaa8b80d450dc6c1d84b4d631/platform/windows/display_server_windows.cpp#L3260-L3271

Missing a mouse up event means pressrc will never again be decremented to 0, so the mouse capture is never properly released. Ideally this should be patched upstream, but I'm not exactly sure what the fix should be, and I still don't have an MRP.

For now, I'll figure out a workaround.

pkdawson commented 1 year ago

The upstream fix has not been merged yet (everyone is busy working on the 4.0 release), so I'll release the workaround for now instead.

https://github.com/godotengine/godot/pull/72720

pkdawson commented 1 year ago

Fix merged, the workaround can be retired for Godot 4.1.0