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 2947

Summary: Android "NullPointerException" in "audioWriteShortBuffer"
Product: SDL Reporter: Sylvain <sylvain.becker>
Component: audioAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED INVALID QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: gabriel+bugzilla-libsdl
Version: 2.0.3   
Hardware: ARM   
OS: Android (All)   

Description Sylvain 2015-04-16 16:50:17 UTC
I have got this error in my android console for a while. 
it occurs very very rarely (but steadily), on various applications and versions.


 java.lang.NullPointerException
 at org.libsdl.app.SDLActivity.audioWriteShortBuffer(SDLActivity.java:line?)
 at dalvik.system.NativeStart.run(Native Method)


Probably "audioWriteShortBuffer" and "audioWriteByteBuffer" are both concerned.

My line number is wrong (I have updated my already-modified-file in the meantime), so I can't say whether the issue is about "mAudioTrack" or "buffer" being "null".
Comment 1 Ryan C. Gordon 2015-06-08 00:06:34 UTC
If you get a chance, let us know the definite line this happens on, because I don't know which thing is NULL that shouldn't be, and under what circumstances.

Thanks,
--ryan.
Comment 2 Sylvain 2015-08-02 08:08:32 UTC
I have updated my app and finally got precisely the line where it fails.

Error is still : 

java.lang.NullPointerException
at org.libsdl.app.SDLActivity.audioWriteShortBuffer(SDLActivity.java:837)
at dalvik.system.NativeStart.run(Native Method)

Android version: Android 4.0.3 - 4.0.4
Android device: Eee Pad TF101 (TF101)


the line is :
 837            int result = mAudioTrack.write(buffer, i, buffer.length - i);
Comment 3 Gabriel Kind 2017-08-27 01:02:15 UTC
I'm observing the same problem, unfortunately not on any of my devices, just through the Google Play crash reports. Only happens on Android 5.0 and newer devices.

By looking at the code I assume the problem is in SDLActivity.java in the function audioOpen. In the error case it sets mAudioTrack to null and later when audioWriteShortBuffer is called mAudioTrack is null.

But just checking for null isn't really a solution because it just hides the problem.

One problem I see is that AudioFormat.CHANNEL_CONFIGURATION_STEREO (value 3) is deprecated since API5 and should be CHANNEL_OUT_STEREO (value 12). Or maybe doubling the buffer size helps, Android makes no sense as usual. Will experiment with this if it resolves the issue...
Comment 4 Gabriel Kind 2017-08-27 22:28:10 UTC
Nope that is not the reason. When I force an audio initialisation failure at this location the application just terminates because the SDL Audio subsystem can't be initialized. So no idea at all what's going wrong here.
Comment 5 Sylvain 2017-09-05 11:03:19 UTC
Hey,
Are you trying with the latest SDL2 code ?
Comment 6 Gabriel Kind 2017-10-24 12:24:37 UTC
Not yet. I just updated my APK to 2.0.6 and wait now for new crash reports. Just saw that 2.0.7 is out, though.
Comment 7 Sylvain 2019-10-23 09:14:46 UTC
Closing it as I don't see it anymore, maybe something in android ...