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 3012 - Android accelerometer joystick axis values overflow when values from Android are larger than gravity
Summary: Android accelerometer joystick axis values overflow when values from Android ...
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: joystick (show other bugs)
Version: HG 2.0
Hardware: All Android (All)
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-06-13 22:15 UTC by Magnus Bjerke Vik
Modified: 2015-06-15 02:25 UTC (History)
0 users

See Also:


Attachments
Patch to fix overflow (1.22 KB, patch)
2015-06-13 22:15 UTC, Magnus Bjerke Vik
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Magnus Bjerke Vik 2015-06-13 22:15:01 UTC
Created attachment 2177 [details]
Patch to fix overflow

This causes issues when for instance using the joystick API to make an Android phone rotate an object by rotating the phone. When the absolute value of an axis reported by android is larger than earth gravity, SDL will overflow the Sint16 value used for joystick axes, causing sporadic movements when close to the gravity. Just holding the phone so that e.g. Y points directly upwards will make it unstable, and even more if you just tap the phone gently from below (increasing the acceleration).

More detailed: SDLActivity gets the accelerometer values in onSensorChanged and divides each axis by earth gravity. SDL_SYS_JoystickUpdate takes each of the axis values, multiplies them by 32767.0 (largest Sint16), and the casts them to Sint16. From this you can see that any value from Android that exceeds earth gravity will overflow the joystick axis.

A fix is to clamp the values so that they won't overflow the Sint16. You can find a patch for this as an attachment.
Comment 1 Sam Lantinga 2015-06-15 02:25:42 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/0ff5994253c2