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 crash when closing SharedCamera (itself) #1602

Open DanPetras opened 1 year ago

DanPetras commented 1 year ago

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

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.

devbridie commented 1 year ago

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