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 2370 - Accelerometer axes return weird/random values
Summary: Accelerometer axes return weird/random values
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: joystick (show other bugs)
Version: 2.0.1
Hardware: ARM Android (All)
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-27 19:04 UTC by Jairo Luiz
Modified: 2014-01-27 21:02 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jairo Luiz 2014-01-27 19:04:43 UTC
I found a bug when a try to read the accelerometer axes on android devices.
The values are a weird/random value for the first axis and 0 for ther others.

I search in the code and found a bug in this line:
https://hg.libsdl.org/SDL/file/af040fdf47e4/src/joystick/android/SDL_sysjoystick.c#l500

The "Android_JNI_GetAccelerometerValues" returns a boolean, indicating if the "values" array are been updated.
But you don't use this boolean. So, in the next lines, you try to read values from a uninitialized array, generating weird/unpredictable results.

I made this change in my project and that solved the problem for now:
https://bitbucket.org/tangerinagames/love-android-sdl2/commits/f4754554774fc92fb5acddab6aee322a670d5ba5?at=accelerometer

Thanks.
Comment 1 Gabriel Jacobo 2014-01-27 20:59:51 UTC
Fixed, thanks! https://hg.libsdl.org/SDL/rev/47f67902b179
Comment 2 Jairo Luiz 2014-01-27 21:02:37 UTC
Great!