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 2437 - SDL_GetRelativeMouseState() acts strange immediately after SDL_SetRelativeMouseMode() on OS X
Summary: SDL_GetRelativeMouseState() acts strange immediately after SDL_SetRelativeMou...
Status: ASSIGNED
Alias: None
Product: SDL
Classification: Unclassified
Component: events (show other bugs)
Version: 2.0.1
Hardware: x86_64 Mac OS X 10.8
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-03-08 00:23 UTC by jbates
Modified: 2017-08-14 20:38 UTC (History)
1 user (show)

See Also:


Attachments
Simple test app demonstraing behavior (958 bytes, text/plain)
2014-03-08 14:14 UTC, jbates
Details
Simple app demonstrating workaround (1.37 KB, text/x-csrc)
2014-03-08 14:24 UTC, jbates
Details

Note You need to log in before you can comment on or make changes to this bug.
Description jbates 2014-03-08 00:23:00 UTC
On OS X (Not Windows or Linux), the first time I call SDL_GetRelativeMouseState() after a call to SDL_SetRelativeMouseMode(SDL_TRUE) acts as if the cursor moved to the center of the window. Also, if I then call SDL_SetRelativeMouseMode(SDL_FALSE) and then SDL_SetRelativeMouseMode(SDL_TRUE) again without any intervening mouse motion events, the first mouse motion event afterwards acts as if the cursor moved from the center of the window back to where it was last visible.

Manually calculating deltas using the non-relative SDL_GetMouseState() yields the same problems.

I managed to get around it in my own application by calling SDL_GetRelativeMouseState(NULL, NULL) immediately after all calls to SDL_SetRelativeMouseMode() and again on the first mouse motion event after.
Comment 1 Sam Lantinga 2014-03-08 04:51:54 UTC
We just recently fixed something similar to this. Can you try in the latest SDL snapshot?
http://www.libsdl.org/tmp/SDL-2.0.zip
Comment 2 jbates 2014-03-08 13:18:22 UTC
(In reply to Sam Lantinga from comment #1)
> We just recently fixed something similar to this. Can you try in the latest
> SDL snapshot?
> http://www.libsdl.org/tmp/SDL-2.0.zip

The snapshot seems to fix the second case, but not the first. Also, with the snapshot build, when the cursor is restored after SDL_SetRelativeMouseMode(SDL_FALSE), it's placed at the center of the window instead of where it was last before SDL_SetRelativeMouseMode(SDL_TRUE). If at all possible, I'd like to keep the old behavior where the cursor coordinates are retained between calls.

Let me see if I can come up with a small example program demonstrating the issue.
Comment 3 jbates 2014-03-08 14:14:12 UTC
Created attachment 1584 [details]
Simple test app demonstraing behavior

Here's a small test app. It outputs to stdout every time SDL_GetRelativeMouseState() returns a dimension whose absolute value is greater than 50. Left mouse down callsSetRelativeMouseMode(SDL_TRUE), and vice-versa for mouse up.

To demonstrate the bug:

1. Press the mouse button somewhere far from the center of the window. Don't move the mouse or release the button. On OS X, it outputs the delta from the cursor to the center of the window. On Linux and Windows, no mouse motion is registered.

2. Release the mouse button. On OS X, it outputs the delta from the center of the window back to where the cursor is restored (in the snapshot build, the cursor is restored to the center of the window, so nothing happens). On Linux and Windows, no mouse motion is registered.

3. Now double-click and hold the mouse button, careful not to move the mouse. Sometimes (I'm not sure of the exact case) the next time you move the mouse while still holding the button, a larger than expected relative mouse motion is reported on OS X.

Bottom line, SDL_GetRelativeMouseState() acts inconsistently after calls to SDL_SetRelativeMouseMode() on OS X.
Comment 4 jbates 2014-03-08 14:24:44 UTC
Created attachment 1585 [details]
Simple app demonstrating workaround

And here's the same app with the workaround I developed. It calls SDL_GetRelativeMouseState(NULL, NULL) just before the cases that were producing the unexpected results. Including it makes my program operate more-consistently between platforms (OS X, Windows, and Linux)