fredsa / playn

Cross platform game library for N≥4 platforms
0 stars 1 forks source link

finish activity causes crash on android #197

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use sounds in appliction
2. finish the activity
3. crahs

What is the expected output? What do you see instead?

The expected outcome is not to crash, but it crashes ;)

What version of the product are you using? On what operating system?

1.5 snapshot on gnex 4.1

Please provide any additional information below.

The problem is when we try to clean up sounds and we stop a mediaplayer that is 
in the wrong state. I am not sure why it is in the wrong state though...

01-06 15:28:00.116: E/AndroidRuntime(2706): Caused by: 
java.lang.IllegalStateException
01-06 15:28:00.116: E/AndroidRuntime(2706):     at 
android.media.MediaPlayer._stop(Native Method)
01-06 15:28:00.116: E/AndroidRuntime(2706):     at 
android.media.MediaPlayer.stop(MediaPlayer.java:832)
01-06 15:28:00.116: E/AndroidRuntime(2706):     at 
playn.android.AndroidCompressedSound.onDestroy(AndroidCompressedSound.java:138)
01-06 15:28:00.116: E/AndroidRuntime(2706):     at 
playn.android.AndroidAudio.onDestroy(AndroidAudio.java:45)
01-06 15:28:00.116: E/AndroidRuntime(2706):     at 
playn.android.GameActivity.onDestroy(GameActivity.java:150)
01-06 15:28:00.116: E/AndroidRuntime(2706):     at 
android.app.ActivityThread.performDestroyActivity(ActivityThread.java:2780)

Original issue reported on code.google.com by alexande...@gmail.com on 24 Jul 2012 at 8:19

GoogleCodeExporter commented 9 years ago
I have same bug in Android. On other platforms everything ok.

1) Problem exists only when sounds used (without sounds, finish() exits 
correctly and you can correctly return to game)

For exit, I'm using next code in a GameActivity:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        PlayN.log().warn("KEYCODE_BACK");
    finish();
    }
}

Also tried onDestroy(), onPause(), platform().audio().onDestroy() there is no 
luck :( same bug :(

Guys, does any body know how correctly close PlayN GameActivity with sound 
using back button?

I also noticed a second bug in Android sound system - you can't load sounds 
before playn.core.Game starts because after calling 
platform().assets().getSound(..) it forcely starts game loop - "Starting game 
loop" message and it crashes with another bug because there are no loops starts 
;| Other platforms works ok.

3) finish() crash stack:

08-31 23:40:25.387: E/AndroidRuntime(1192): FATAL EXCEPTION: main
08-31 23:40:25.387: E/AndroidRuntime(1192): java.lang.RuntimeException: Unable 
to destroy activity {playn.android/playn.android.Loader}: 
java.lang.IllegalStateException
08-31 23:40:25.387: E/AndroidRuntime(1192):     at 
android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3273)
08-31 23:40:25.387: E/AndroidRuntime(1192):     at 
android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3291)
08-31 23:40:25.387: E/AndroidRuntime(1192):     at 
android.app.ActivityThread.access$1200(ActivityThread.java:130)
08-31 23:40:25.387: E/AndroidRuntime(1192):     at 
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1248)
08-31 23:40:25.387: E/AndroidRuntime(1192):     at 
android.os.Handler.dispatchMessage(Handler.java:99)
08-31 23:40:25.387: E/AndroidRuntime(1192):     at 
android.os.Looper.loop(Looper.java:137)
08-31 23:40:25.387: E/AndroidRuntime(1192):     at 
android.app.ActivityThread.main(ActivityThread.java:4745)
08-31 23:40:25.387: E/AndroidRuntime(1192):     at 
java.lang.reflect.Method.invokeNative(Native Method)
08-31 23:40:25.387: E/AndroidRuntime(1192):     at 
java.lang.reflect.Method.invoke(Method.java:511)
08-31 23:40:25.387: E/AndroidRuntime(1192):     at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-31 23:40:25.387: E/AndroidRuntime(1192):     at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-31 23:40:25.387: E/AndroidRuntime(1192):     at 
dalvik.system.NativeStart.main(Native Method)
08-31 23:40:25.387: E/AndroidRuntime(1192): Caused by: 
java.lang.IllegalStateException
08-31 23:40:25.387: E/AndroidRuntime(1192):     at 
android.media.MediaPlayer._stop(Native Method)
08-31 23:40:25.387: E/AndroidRuntime(1192):     at 
android.media.MediaPlayer.stop(MediaPlayer.java:1038)
08-31 23:40:25.387: E/AndroidRuntime(1192):     at 
playn.android.AndroidCompressedSound.onDestroy(AndroidCompressedSound.java:138)
08-31 23:40:25.387: E/AndroidRuntime(1192):     at 
playn.android.AndroidAudio.onDestroy(AndroidAudio.java:45)
08-31 23:40:25.387: E/AndroidRuntime(1192):     at 
playn.android.GameActivity.onDestroy(GameActivity.java:150)
08-31 23:40:25.387: E/AndroidRuntime(1192):     at 
android.app.Activity.performDestroy(Activity.java:5172)
08-31 23:40:25.387: E/AndroidRuntime(1192):     at 
android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1109)
08-31 23:40:25.387: E/AndroidRuntime(1192):     at 
android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3260)
08-31 23:40:25.387: E/AndroidRuntime(1192):     ... 11 more

Original comment by 7221...@gmail.com on 31 Aug 2012 at 7:54

GoogleCodeExporter commented 9 years ago
Fixed in 
https://github.com/threerings/playn/commit/627cb3eb3d9904d5c468ea00927ae48a8c750
3ad

Original comment by m...@samskivert.com on 1 Oct 2012 at 4:33