Pablo
Pablo

Reputation: 128

ANR error with libgdx on pause/resume

I have an app running at android market and I have received 2 ANR logs.

Different ANR names, but same place (AndroidGraphics.java:404). I don't know what to do. ¿Can anyone help me?

Thanks!

Stack 1: ANR keyDispatchingTimedOut

JNI: CheckJNI is off; workarounds are off; pins=0; globals=192 (plus 11 weak)

DALVIK THREADS:
(mutexes: tll=0 tsl=0 tscl=0 ghl=0)

"main" prio=5 tid=1 WAIT
| group="main" sCount=1 dsCount=0 obj=0x42058578 self=0x41522120
| sysTid=15043 nice=0 sched=0/0 cgrp=apps handle=1074204668
| state=S schedstat=( 0 0 0 ) utm=1257 stm=809 core=2
at java.lang.Object.wait(Native Method)
- waiting on <0x42928d90> (a java.lang.Object)
at java.lang.Object.wait(Object.java:364)
at com.badlogic.gdx.backends.android.AndroidGraphics.pause(AndroidGraphics.java:404)
at com.badlogic.gdx.backends.android.AndroidApplication.onPause(AndroidApplication.java:217)
at com.packetname.gameName.MainActivity.onPause(MainActivity.java:124)
at android.app.Activity.performPause(Activity.java:5235)
at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1233)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3050)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3019)
at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2997)
at android.app.ActivityThread.access$800(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1267)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)

Stack 2: ANR Broadcast of Intent { act=android.intent.action.SCREEN_OFF flg=0x50000010 }

    DALVIK THREADS:
    (mutexes: tll=0 tsl=0 tscl=0 ghl=0)

"main" prio=5 tid=1 WAIT
| group="main" sCount=1 dsCount=0 obj=0x40ba7568 self=0x40b97a18
| sysTid=1566 nice=0 sched=0/0 cgrp=apps handle=1075324464
| schedstat=( 267164153 509750763 1051 ) utm=17 stm=9 core=1
at java.lang.Object.wait(Native Method)
- waiting on <0x411f0908> (a java.lang.Object)
at java.lang.Object.wait(Object.java:364)
at com.badlogic.gdx.backends.android.AndroidGraphics.pause(AndroidGraphics.java:404)
at com.badlogic.gdx.backends.android.AndroidApplication.onPause(AndroidApplication.java:217)
at com.packetname.gameName.MainActivity.onPause(MainActivity.java:102)
at android.app.Activity.performPause(Activity.java:5106)
at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1225)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2825)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2794)
at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2772)
at android.app.ActivityThread.access$800(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1206)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)

Upvotes: 3

Views: 3500

Answers (1)

P.T.
P.T.

Reputation: 25177

Something in your render code path is hanging, or is just taking too long.

The stack traces you show are for the main android thread, which in Libgdx, is different from the render thread that runs your libgdx code. See https://code.google.com/p/libgdx/wiki/TheArchitecture#The_Application. What happens in the pause path is

  1. Android asks the main thread to pause
  2. The main thread asks the libgdx render thread to pause (see onPause at AndroidApplication.java line 214), this calls graphics.pause()
  3. graphics.pause() (see AndroidGraphics.java line 409), sets the pause flag and spins until the flag is cleared.
  4. The pause flag is cleared by the render thread in the render loop (see onDrawFrame in AndroidGraphics).

If your render loop is stuck somewhere, then the pause flag will never be cleared, and the main thread won't wake up and Android will kill your app.

So the backtrace you show just includes the first three steps (on the Android thread) and not the interesting backtrace.

Hopefully the crash reports include backtraces for the other threads in your system.

If this is a rare crash, it could be that your render loop gets hung up somewhere (having nothing to do with the pause code), the user gets annoyed, and tries to switch contexts, and Android tries to pause the system, and then Android gets angry and kills your app. This is why you should never do anything really slow (like waiting for a network response or reading a lot from slow storage) on your render thread: the user might pause at any time, and expect your render thread to execute the pause action quickly.

Upvotes: 1

Related Questions