libgdx-oboe icon indicating copy to clipboard operation
libgdx-oboe copied to clipboard

Crash when starting app on some devices

Open dasisdormax opened this issue 2 years ago • 3 comments

Hello and first of all, Thanks for creating this library!

Using libgdx-oboe from current master, my game crashes when launching on some, but not all of my devices. The error happens on a OnePlus 6 running Android 11. This is the message:

java.lang.RuntimeException: Unable to resume activity {...}: com.badlogic.gdx.utils.GdxRuntimeException: Error starting stream: ErrorInvalidState
        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4636)
        at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4668)
        at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
        at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2251)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:233)
        at android.app.ActivityThread.main(ActivityThread.java:8068)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)
     Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Error starting stream: ErrorInvalidState
        at barsoosayque.libgdxoboe.OboeAudio.resume(Native Method)
        at com.badlogic.gdx.backends.android.AndroidApplication.onResume(AndroidApplication.java:265)
        at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1571)
        at android.app.Activity.performResume(Activity.java:8141)
        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4626)
        at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4668) 
        at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52) 
        at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2251) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:233) 
        at android.app.ActivityThread.main(ActivityThread.java:8068) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978) 

When rolling back to commit c09f42c22850275d32a63922ea49a76dd6b545d4, the app works normal on my devices. So this looks like an error introduced when fixing issue #12.

When researching a bit more I found out:

  • That device calls resume when launching the app while other devices don't
  • Calling audio.resume() twice crashes the app

Changing the resume function to do nothing instead of crashing when already resumed would seem like a good solution to me.

dasisdormax avatar Jul 24 '22 09:07 dasisdormax

Oh, thanks for the detailed report. Yeah, seems like starting an oboe stream too early could lead to crashes on some devices (the audio stack on android is cursed indeed). I admit I didn't research much before fixing #12. I'll try to look into it more

barsoosayque avatar Jul 24 '22 17:07 barsoosayque

Finally, I got time for this issue. I'm still not sure what is wrong, but I made internal oboe checks to log warnings instead of throwing an exception so it won't crash. But I assume that in those rare cases when it were crashing before, now it just wouldn't play any sound. Can you test the current master ? I just don't seem to reproduce this issue myself

barsoosayque avatar Oct 12 '22 16:10 barsoosayque

Hi. I finally got to try the current master build.

I did not get any crashes with this build. However, I sometimes had no music playing initially (this time on my weak Amazon tablet), with the audio starting later once another sound is scheduled.

I think this is not as bad and much better than having crashes sometimes. Thanks for your fix!

dasisdormax avatar Nov 10 '22 09:11 dasisdormax