SDL grabs the mouse when calling SDL_SetRelativeMouseMode(SDL_TRUE) or
When breaking into the debugger, it is not released, at least on
Linux/X11, which is kinda annoying.
SDL itself can’t do anything about this: When the debugger takes over,
your application (or SDL) can’t do anything, not even release the mouse.
However, gdb allows you to call functions in your program, so you can
alt-tab (or something) to the terminal gdb is running in and enter "call
For SDL_SetWindowGrab() it’s harder because you also need the window
handle - if you use that I’d suggest that you create a function like
DEBUG_UngrabMouse() that calls SDL_SetWindowGrab(yourWindowHandle, 0) so
you can just “call DEBUG_UngrabMouse()” from gdb.
(In theory it should also be possible to send an XF86Ungrab key event,
e.g. with “xdotool key XF86Ungrab”, but at least on my system that
Anyway, you still need to get to the gdb prompt and especially if you’re
not running gdb in a terminal but from a GUI like Eclipse CDT, QTCreator
or whatever, this is pretty hard.
Fortunately, gdb has a python scripting API that allows you to execute
python functions whenever you break into the debugger.
So the awesome KittyCat in #SDL (who isn’t signed up in this ML) wrote a
python-script which hooks into those events and releases the mouse, see
To use it, put the python code in a file named
yourexecutablename-gdb.py, next to the executable you wanna debug.
So if your debug-executable is /path/to/your/project/MyGame, you copy
the script to /path/to/your/project/MyGame-gdb.py
Furthermore you need to allow gdb to execute it, you can do that by
adding the line
to $HOME/.gdbinit - that will allow gdb to load python scripts from that
path and all its (direct and indirect) subdirectories.
If you use SDL_SetWindowGrab(), it won’t work out of the box (because
there is no way to get the SDL_Window* handle in gdb that works for all
projects), in that case write a DEBUG_UngrabMouse() function as
described above and modify the script to call it.
-------------- next part --------------
A non-text attachment was scrubbed…
Size: 1181 bytes
Desc: not available