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 735

Summary: SDL_WaitEvent() does not lock X11 display
Product: SDL Reporter: pelya <x.pelya.x>
Component: eventsAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED INVALID QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: ich
Version: 1.2.13Keywords: target-1.2.14
Hardware: x86   
OS: Linux   

Description pelya 2009-04-28 08:26:04 UTC
I have several threads in my game (OpenLieroX), main thread does video flipping stuff and contains SDL_WaitEvent() call. Actual processing is done into another thread, which uses X11 functions such as clipboard and flashing window in taskbar.
Before using these functions I always call SDL_SysWMinfo.info.x11.lock_func(), but it keeps crashing due to race condition, because this lock function is not called from SDL_WaitEvent() which also calls X11 functions.
I can move all my X11 code into main thread, but I think that's rather bug in SDL, because you're giving some API and don't using it yourselves. Or at least put a warning about that into documentation.
Comment 1 Albert Zeyer 2009-04-28 09:19:12 UTC
Note: This is the specific bug report in our game:
http://sourceforge.net/tracker/?func=detail&atid=891648&aid=2744753&group_id=180059

This is the backtrace:
#0 0xb7f9b430 in __kernel_vsyscall ()
#1 0xb797c8a0 in raise () from /lib/tls/i686/cmov/libc.so.6
#2 0xb797e268 in abort () from /lib/tls/i686/cmov/libc.so.6
#3 0xb797572e in __assert_fail () from /lib/tls/i686/cmov/libc.so.6
#4 0xb7c13424 in _XGetXCBBuffer () from /usr/lib/libX11.so.6
#5 0xb7c14843 in _XSend () from /usr/lib/libX11.so.6
#6 0xb7c14a02 in _XFlush () from /usr/lib/libX11.so.6
#7 0xb7bebf61 in XFlush () from /usr/lib/libX11.so.6
#8 0xb7f25dae in ?? () from /usr/lib/libSDL-1.2.so.0
#9 0xb7f297b2 in ?? () from /usr/lib/libSDL-1.2.so.0
#10 0xb7f2aaab in ?? () from /usr/lib/libSDL-1.2.so.0
#11 0xb7ef7f9d in SDL_PumpEvents () from /usr/lib/libSDL-1.2.so.0
#12 0xb7ef83db in SDL_WaitEvent () from /usr/lib/libSDL-1.2.so.0
#13 0x0818b8e1 in main (argc=10, argv=0xbf89c234) at
/home/pelya/src/endless_space/openlierox/src/main.cpp:380

And it crashes because of this:
_XGetXCBBuffer: Assertion `((int) ((xcb_req) - (dpy->request)) >= 0)'
Comment 2 pelya 2009-04-28 09:28:29 UTC
I've looked into SDL_SysWMInfo.info.x11.lock_func() and it actually locks
the SDL event thread, not calls XLockDisplay(), so my assumption was wrong.
Why does it crash anyway then?
Comment 3 pelya 2009-05-18 09:02:29 UTC
I've moved all X11 code to main thread, the game stopped crashing after that.
But there should be note inside SDL documentation about that case.
Comment 4 Ryan C. Gordon 2009-09-13 16:33:28 UTC
Tagging this bug with "target-1.2.14" so we can try to resolve it for SDL 1.2.14.

Please note that we may choose to resolve it as WONTFIX. This tag is largely so we have a comprehensive wishlist of bugs to examine for 1.2.14 (and so we can close bugs that we'll never fix, rather than have them live forever in Bugzilla).

--ryan.