google-ar / arcore-android-sdk

ARCore SDK for Android Studio
https://developers.google.com/ar
Other
4.98k stars 1.22k forks source link

ARCore 1.32 crash issue #1546

Open Fil-Niantic opened 2 years ago

Fil-Niantic commented 2 years ago

Lightship ARDK upgraded its dependency of ARCore from 1.22 to 1.32, and since then ARCore has been causing Android apps to crash from a

JNI DETECTED ERROR IN APPLICATION: a thread (tid 8505 is making JNI calls without being attached in call to DeleteGlobalRef

Similar bugs reported in:

https://github.com/google-ar/arcore-android-sdk/issues/1359 https://github.com/google-ar/arcore-android-sdk/issues/1315#issuecomment-978090263 These reports' crash logs are consistent with the crash log that we observed. (crash logs attached below)

What we tried

This crash occurs when Lightship ARDK attempts to destroy the ar session. Looking at several FATAL EXCEPTION stack traces, we observe that the crash eventually stems from ARCore making an internal call to /data/app/com.google.ar.core-GbjQW20pppfXgk8JnlTwEQ==/base.apk (ArSession_destroy+92) (we have attached several logs to this that shows the stack traces)

For additional context, we have observed that this crash on ar session destruction happens only if the following occurs.

  1. Initialize the ar session via calling ArSession_create() ArCore function
  2. Immediately then pause the ar session via calling ArSession_pause() ArCore function (before first camera feed buffer is rendered)
  3. Destroy the ar session via calling ArSession_destroy() ArCore function some time later (where crash occurs)

Note: if the session is not paused immediately in step 2 and the session is later destroyed, then the crash doesn’t repro (we were able to workaround the crash by adding a 1 second delay before pausing the session)

So far, we have been able to repro this crash with the similar crash stack trace stemming from ArCore on 3 different apps (hence 3 logs below) that depend on Lightship ARDK (and hence the upgraded ArCore 1.32)

In the attached logs, searching Deleting ArSession... will show that arcore is attempting to destroy the ar session from session_lite_c_api.cc:37 (arcore class) but then runs into Unable to delete global reference, JNIEnv* missing, which eventually causes the above mentioned JNI error

Error logs

arvoyage_crash.txt ardkexamples_plane_anchors_app_crash.txt wayfarer-crash.txt

adb shell pm dump com.google.ar.core | egrep versionName\|versionCode\|packages: | grep -v APEX returns:

    versionCode=222640293 minSdk=31 targetSdk=33
    versionName=1.34.222640293
Hidden system packages:
    versionCode=0 minSdk=24 targetSdk=30
    versionName=0
    # of packages: 1 / # of packages in DATA: 1 (3)

adb shell getprop ro.build.fingerprint returns: samsung/o1quew/o1q:12/SP1A.210812.016/G991U1UES5CVI8:user/release-keys

log.txt

devbridie commented 2 years ago

Hey, could you take a look at an attempt to repro: 6b4b0bae6afe77c41ed2412003cee0227581cbc1. I couldn't tell if you also resuming before pausing, but removing the call to resume has no effect).

I'm also testing with Don't keep activities enabled, ensuring that ArSession_destroy is called (and verifying this with the I1546 log).

Could you help me understand if this patch would repro?