arcore-android-sdk icon indicating copy to clipboard operation
arcore-android-sdk copied to clipboard

ARCore crash when closing SharedCamera (itself)

Open DanPetras opened this issue 2 years ago • 1 comments

SPECIFIC ISSUE ENCOUNTERED

Crash when CameraDevice.StateCallback.onError in called while using Session.Feature.SHARED_CAMERA

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.os.Handler.removeCallbacksAndMessages(java.lang.Object)' on a null object reference com.google.ar.core.SharedCamera.close(SharedCamera.java:1) com.google.ar.core.SharedCamera.-$$Nest$mclose(SharedCamera.java:0) com.google.ar.core.ai.onError(SharedCamera.java:2) android.hardware.camera2.impl.CameraDeviceImpl$8.run(CameraDeviceImpl.java:420) android.os.Handler.handleCallback(Handler.java:942) android.os.Handler.dispatchMessage(Handler.java:99) android.os.Looper.loopOnce(Looper.java:211) android.os.Looper.loop(Looper.java:300) android.os.HandlerThread.run(HandlerThread.java:67)

Related "source code" in ARCore:

class SharedCamera {
    private void close() {
        // Next line is causing the crash if close is called multiple times for some reason
        this.sharedCameraHandler.removeCallbacksAndMessages((Object)null);
        this.sharedCameraHandler.getLooper().quit();
        this.sharedCameraHandler = null;
    }
}

VERSIONS USED

  • Android Studio: Android Studio Giraffe | 2022.3.1
  • ARCore SDK for Android: 1.38.0
  • Device manufacturer, model, and O/S: Various, Android 12 / 13
  • Google Play Services for AR (ARCore): Unknown (Crashlytics crash)

ADDITIONAL COMMENTS

When encountering CameraDevice.StateCallback.onError in our application we are already doing the cleanup:

com.google.ar.core.Session.pause()
android.hardware.camera2.CameraDevice.close()
com.google.ar.core.Session.close() // called on bg thread

It seems like ARCore itself is also trying to close the SharedCamera which was already closed by the app.

DanPetras avatar Aug 17 '23 09:08 DanPetras

Thanks for the report. A fix for this is going in in 1.40.0.

devbridie avatar Aug 17 '23 17:08 devbridie