We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3409

Summary: SDL enters infinite loop in X11_SetWindowGrab
Product: SDL Reporter: Jason Wyatt <jwyatt>
Component: videoAssignee: Ryan C. Gordon <icculus>
Status: ASSIGNED --- QA Contact: Sam Lantinga <slouken>
Severity: blocker    
Priority: P2 CC: jwyatt
Version: 2.0.4Keywords: target-2.0.6
Hardware: x86_64   
OS: Linux   
Attachments: Demo for hang.

Description Jason Wyatt 2016-08-17 10:52:12 UTC
Created attachment 2549 [details]
Demo for hang.

If relative mouse mode is on, and SDL_ShowWindow is followed by SDL_HideWindow without a call to SDL_PumpEvents in between, the SDL enters an infinite loop.
This is because SDL will call X11_SetWindowGrab in response to the focus in event that resulted from SDL_ShowWindow. X11_SetWindowGrab will call XGrabPointer until it returns GrabSuccess. However the window is now hidden, so XGrabPointer will always return GrabNotViewable.
Comment 1 Jason Wyatt 2016-08-17 11:26:55 UTC
Actually, calling SDL_PumpEvents after SDL_HideWindow() always seems to cause this hang, because SDL_HideWindow() causes the following series of events:

UnmapNotify event, serial 27, synthetic NO, window 0x2400005,
    event 0x2400005, window 0x2400005, from_configure NO

FocusOut event, serial 27, synthetic NO, window 0x2400005,
    mode NotifyNormal, detail NotifyNonlinear

FocusIn event, serial 27, synthetic NO, window 0x2400005,
    mode NotifyNormal, detail NotifyPointer
Comment 2 Jason Wyatt 2016-08-17 15:06:04 UTC
With relative mouse mode disabled:

SDL_HideWindow(window)
SDL_PumpEvents()
SDL_SetRelativeMouseMode(SDL_TRUE)

will also cause the hang, because the focus is still set to the hidden window.
Comment 3 Jason Wyatt 2017-07-21 09:58:56 UTC
https://hg.libsdl.org/SDL/rev/79be3e82dcf1 prevents the infinite loops. However it makes it impossible to grab the cursor again if the grab fails.

https://hg.libsdl.org/SDL/rev/7cfe088fafba somewhat reduces the chances of coming across this issue, since the hidden state of a window is now properly reflected. However it still seems to be possible to cause the grab to fail (I haven't narrowed this down beyond rapid window interaction while SDL tries to set the mouse grab).
Comment 4 Ryan C. Gordon 2017-08-25 15:07:15 UTC
I think we should punt on this for 2.0.6.