[SDL] SDL_MOUSEMOTION bug?

Ryan C. Gordon icculus at icculus.org
Tue Oct 17 22:13:30 PDT 2006


> When the application starts if the mouse is hidden and happens to be over
> the window then the xrel/yrel contain actually the absolute and not the
> relative position of the mouse. If I start the application so that the mouse
> happens to be outside of the window or the mouse is not hidden the problem
> disappears. So the two condition must be met: mouse hidden + grab mouse
> while the pointer is in the window.

Actually, it doesn't appear to be the grab itself...if I remove the 
calls to SDL_ShowCursor() and SDL_WM_GrabInput(), it still gives the 
bogus motion event, if the cursor is in the area where the window gets 
created.

This is a bug in SDL, but the quickest fix is to add this to your code, 
right after SDL_SetVideoMode()...

    { SDL_Event e; while (SDL_PollEvent(&e)) {} }

...which will flush any existing events before your program really gets 
started. A proper fix would probably do something similar at the end of 
SDL_SetVideoMode() inside SDL itself.

This is in the bug tracker now:
   http://bugzilla.libsdl.org/show_bug.cgi?id=347

...and also related:
   http://bugzilla.libsdl.org/show_bug.cgi?id=348

--ryan.





More information about the SDL mailing list