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

Summary: Accelerometer axes return weird/random values
Product: SDL Reporter: Jairo Luiz <jairo.luiz>
Component: joystickAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: gabomdq, martin
Version: 2.0.1   
Hardware: ARM   
OS: Android (All)   

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!