After upgrading from v3.3.2 to 3.4.1 we saw a huge spike of ANR in our game.
Operating systems: only Android 11 and 12
Device states: 60% background
Log:
main (native): tid=1 systid=11328
#00 pc 0x4deb0 libc.so
#01 pc 0x52954 libc.so
#02 pc 0xb6070 libc.so
#03 pc 0x17cbdec split_config.arm64_v8a.apk!libcocos.so
#04 pc 0x82ab64 split_config.arm64_v8a.apk!libcocos.so
#05 pc 0x2d7644 libart.so
#06 pc 0x2cdd64 libart.so
#07 pc 0x2f23d0 libart.so
#08 pc 0x2f121c libart.so
#09 pc 0x3feaf0 libart.so
#10 pc 0x2c8514 libart.so
#11 pc 0x2b24a2 base.vdex
#12 pc 0x27d748 libart.so
#13 pc 0x27c8f0 libart.so
#14 pc 0x2d7778 libart.so
at com.cocos.lib.CocosActivity.onSurfaceDestroyNative(CocosActivity.java)
at com.cocos.lib.CocosActivity.surfaceDestroyed(CocosActivity.java:240)
at android.view.SurfaceView.notifySurfaceDestroyed(SurfaceView.java:2161)
at android.view.SurfaceView.updateSurface(SurfaceView.java:1309)
at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:415)
at android.view.View.dispatchWindowVisibilityChanged(View.java:15475)
at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1637)
at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1637)
at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1637)
at com.android.internal.policy.DecorView.dispatchWindowVisibilityChanged(DecorView.java:4667)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3367)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2819)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:10304)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1063)
at android.view.Choreographer.doCallbacks(Choreographer.java:845)
at android.view.Choreographer.doFrame(Choreographer.java:780)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1048)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8582)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:563)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1133)
recommend you to upgrade to version 3.4.2 to test it.
Thank you. We did and as we see in the 3.4.2 the issue appears less often under Android 12, but still exists:
v3.4.1 (1117 ANR events):
Android 12: 56%
Android 11: 44%
v3.4.2 (581 ANR events):
Android 12: 16%
Android 11: 84%
Also the issue always happens right away when you start the game.
All logs from Firebase Crashlytics looks like this:
The ANR occurs only on the app start and even before we can see the splash screen.
And this happens very randomly!
We catched it several times on our test device. We assume the problem is related to DeviceAgent::doInit(const DeviceInfo &info) in the source file: /resources/3d/engine-native/cocos/renderer/gfx-agent/DeviceAgent.cpp and method setMultithreaded(true);
When the ANR occurs, we don’t see message Device thread detached. in debug logs, so we assume that this code is never executed actor->bindContext(true);