mrousavy / react-native-vision-camera

šŸ“ø A powerful, high-performance React Native Camera library.
https://react-native-vision-camera.com
MIT License
7.55k stars 1.1k forks source link

[Android] Vision Camera crashing when opening native camera while Barcodescan is mounted šŸ› #2224

Closed xtl-geiger closed 10 months ago

xtl-geiger commented 11 months ago

What's happening?

During scanning barcodes, despite setting the Camera component inactive, starting a native camera intent is crashing vision camera.

Reproduceable Code

<Camera
              codeScanner={codeScanner}
              device={device}
              format={format}
              torch={cameraFlashMode.mode}
              style={StyleSheet.absoluteFill}
              orientation={cameraOrientation}
              isActive={isActive}
            />

Relevant log output

11-27 14:30:06.203  5864  9427 W SurfaceTextureRenderer: Surface abandoned, dropping frame. 
11-27 14:30:06.203  5864  9427 W SurfaceTextureRenderer: android.hardware.camera2.legacy.LegacyExceptionUtils$BufferQueueAbandonedException
11-27 14:30:06.203  5864  9427 W SurfaceTextureRenderer:        at android.hardware.camera2.legacy.LegacyCameraDevice.getSurfaceId(LegacyCameraDevice.java:744)
11-27 14:30:06.203  5864  9427 W SurfaceTextureRenderer:        at android.hardware.camera2.legacy.LegacyCameraDevice.getSurfaceIds(LegacyCameraDevice.java:773)
11-27 14:30:06.203  5864  9427 W SurfaceTextureRenderer:        at android.hardware.camera2.legacy.SurfaceTextureRenderer.drawIntoSurfaces(SurfaceTextureRenderer.java:777)
11-27 14:30:06.203  5864  9427 W SurfaceTextureRenderer:        at android.hardware.camera2.legacy.GLThreadManager$1.handleMessage(GLThreadManager.java:110)
11-27 14:30:06.203  5864  9427 W SurfaceTextureRenderer:        at android.os.Handler.dispatchMessage(Handler.java:102)
11-27 14:30:06.203  5864  9427 W SurfaceTextureRenderer:        at android.os.Looper.loop(Looper.java:164)
11-27 14:30:06.203  5864  9427 W SurfaceTextureRenderer:        at android.os.HandlerThread.run(HandlerThread.java:65)
11-27 14:30:06.209  5864  9427 E Legacy-CameraDevice-JNI: LegacyCameraDevice_nativeGetSurfaceId: Could not retrieve native Surface from surface.

11-27 14:30:06.229  5864  9421 I RequestQueue: Repeating capture request cancelled.

11-27 14:30:06.230  5864  9421 I CameraDeviceState: Legacy camera service transitioning to state IDLE

11-27 14:30:06.251  5864  5864 I CameraSession: Updating CameraSession Configuration...

11-27 14:30:06.279  5864  5864 I CameraSession: Configuring Session for Camera #0...
11-27 14:30:06.279  5864  5864 I SurfaceOutput: Closing BarcodeScanner..
11-27 14:30:06.280  5864  9399 I CreateCaptureSession: Camera 0: Capture Session #1001 closed!
11-27 14:30:06.280  5864  5864 I BufferQueueConsumer: [ImageReader-1280x720f23m2-5864-1](this:0x77ee91d800,id:4,api:4,p:5864,c:-1) disconnect(C)
11-27 14:30:06.281  5864  9399 I CameraDeviceState: Legacy camera service transitioning to state CONFIGURING
11-27 14:30:06.281  5864  5864 I BufferQueue: [ImageReader-1280x720f23m2-5864-1](this:0x77ee91d800,id:4,api:4,p:5864,c:-1) ~BufferQueueCore
11-27 14:30:06.282  5864  9421 I RequestThread-0: Configure outputs: 0 surfaces configured.

11-27 14:30:06.296  5864  5864 I CameraSession: Adding 1280 x 720 CodeScanner Output in Format #35...
11-27 14:30:06.296  5864  9467 D BufferQueueProducer: [SurfaceTexture-1-5864-3](this:0x77e9cd4000,id:5,api:4,p:1948,c:5864) cancelBuffer: slot 3

11-27 14:30:06.299  5864  5864 I BufferQueue: [unnamed-5864-6](this:0x77ee91d800,id:6,api:0,p:-1,c:-1) BufferQueue core=(5864:de.xtl.kurier)
11-27 14:30:06.299  5864  9550 W DynamiteModule: Local module descriptor class for com.google.mlkit.dynamite.barcode not found.

11-27 14:30:06.299  5864  5864 W GuiExt  : Cannot find GuiExtService
11-27 14:30:06.299  5864  5864 I BufferQueueConsumer: [unnamed-5864-6](this:0x77ee91d800,id:6,api:0,p:-1,c:5864) connect(C): consumer=(5864:de.xtl.kurier) controlledByApp=true
11-27 14:30:06.299  5864  5864 I BufferQueueConsumer: [unnamed-5864-6](this:0x77ee91d800,id:6,api:0,p:-1,c:5864) setConsumerName: unnamed-5864-6

11-27 14:30:06.299  5864  5864 I BufferQueueConsumer: [ImageReader-1280x720f23m2-5864-2](this:0x77ee91d800,id:6,api:0,p:-1,c:5864) setConsumerName: ImageReader-1280x720f23m2-5864-2
11-27 14:30:06.299  5864  5864 I BufferQueueConsumer: [ImageReader-1280x720f23m2-5864-2](this:0x77ee91d800,id:6,api:0,p:-1,c:5864) setDefaultBufferSize: width=1280 height=720

11-27 14:30:06.320  5864  5864 I CreateCaptureSession: Camera 0: Creating Capture Session #1002... Hardware Level: 2} | Outputs: [android.hardware.camera2.params.OutputConfiguration@192faece]
11-27 14:30:06.320  5864  5864 I CreateCaptureSession: Using legacy API (<28)
11-27 14:30:06.320  5864  9401 I Camera  : handleMessage: 1
11-27 14:30:06.320  5864  9401 E Camera  : Error 2
11-27 14:30:06.320  5864  9401 I RequestThread-0: Flushing all pending requests.
11-27 14:30:06.320  5864  9550 I DynamiteModule: Considering local module com.google.android.gms.vision.barcode:0 and remote module com.google.android.gms.vision.barcode:234414000
11-27 14:30:06.320  5864  9401 E RequestQueue: cancel failed: no repeating request exists.
11-27 14:30:06.320  5864  9550 I DynamiteModule: Selected remote version of com.google.android.gms.vision.barcode, version >= 234414000
11-27 14:30:06.320  5864  9401 I CameraDeviceState: Legacy camera service transitioning to state ERROR
11-27 14:30:06.320  5864  9550 V DynamiteModule: Dynamite loader version >= 2, using loadModule2NoCrashUtils

11-27 14:30:06.330  5864  5938 D BufferQueueProducer: [SurfaceTexture-1-5864-3](this:0x77e9cd4000,id:5,api:4,p:1948,c:5864) cancelBuffer: slot 5

11-27 14:30:06.333  5864  5938 D BufferQueueProducer: [SurfaceTexture-1-5864-3](this:0x77e9cd4000,id:5,api:4,p:1948,c:5864) cancelBuffer: slot 6

11-27 14:30:06.339  5864  5938 D BufferQueueProducer: [SurfaceTexture-1-5864-3](this:0x77e9cd4000,id:5,api:4,p:1948,c:5864) cancelBuffer: slot 4

11-27 14:30:06.358  5864  9434 W Vision  : Would have logged:
11-27 14:30:06.358  5864  9434 W Vision  : # m.aox@47b13183

11-27 14:30:06.373  5864  9467 D BufferQueueProducer: [SurfaceTexture-1-5864-3](this:0x77e9cd4000,id:5,api:4,p:1948,c:5864) cancelBuffer: slot 2

11-27 14:30:06.375  5864  9467 D BufferQueueProducer: [SurfaceTexture-1-5864-3](this:0x77e9cd4000,id:5,api:4,p:1948,c:5864) cancelBuffer: slot 7

11-27 14:30:06.376  5864  9467 D BufferQueueProducer: [SurfaceTexture-1-5864-3](this:0x77e9cd4000,id:5,api:4,p:1948,c:5864) cancelBuffer: slot 1
11-27 14:30:06.376  5864  9467 D BufferQueueProducer: [SurfaceTexture-1-5864-3](this:0x77e9cd4000,id:5,api:4,p:1948,c:5864) cancelBuffer: slot 3

11-27 14:30:06.377  5864  9467 D BufferQueueProducer: [SurfaceTexture-1-5864-3](this:0x77e9cd4000,id:5,api:4,p:1948,c:5864) cancelBuffer: slot 5

11-27 14:30:06.378  5864  9467 D BufferQueueProducer: [SurfaceTexture-1-5864-3](this:0x77e9cd4000,id:5,api:4,p:1948,c:5864) cancelBuffer: slot 6

11-27 14:30:06.381  5864  9421 D Camera  : app passed NULL surface

11-27 14:30:06.417  5864  5875 I zygote64: Background concurrent copying GC freed 10475(1018KB) AllocSpace objects, 9(7MB) LOS objects, 22% free, 20MB/26MB, paused 259us total 361.638ms

11-27 14:30:06.492  5864  9467 I BufferQueueProducer: [SurfaceTexture-1-5864-3](this:0x77e9cd4000,id:5,api:4,p:1948,c:5864) disconnect(P): api 4
11-27 14:30:06.492  5864  9467 I BufferQueueConsumer: [SurfaceTexture-1-5864-3](this:0x77e9cd4000,id:5,api:4,p:-1,c:5864) getReleasedBuffers: returning mask 0xffffffffffffffff

11-27 14:30:06.500  5864  5984 I CameraDevices: Camera #0: Available!

11-27 14:30:06.502  5864  9421 W RequestThread-0: Failed to clear prior SurfaceTexture, may cause GL deadlock: 
11-27 14:30:06.502  5864  9421 W RequestThread-0: java.io.IOException: setPreviewTexture failed
11-27 14:30:06.502  5864  9421 W RequestThread-0:       at android.hardware.Camera.setPreviewTexture(Native Method)
11-27 14:30:06.502  5864  9421 W RequestThread-0:       at android.hardware.camera2.legacy.RequestThreadManager.configureOutputs(RequestThreadManager.java:360)
11-27 14:30:06.502  5864  9421 W RequestThread-0:       at android.hardware.camera2.legacy.RequestThreadManager.-wrap0(Unknown Source:0)
11-27 14:30:06.502  5864  9421 W RequestThread-0:       at android.hardware.camera2.legacy.RequestThreadManager$5.handleMessage(RequestThreadManager.java:721)
11-27 14:30:06.502  5864  9421 W RequestThread-0:       at android.os.Handler.dispatchMessage(Handler.java:102)
11-27 14:30:06.502  5864  9421 W RequestThread-0:       at android.os.Looper.loop(Looper.java:164)
11-27 14:30:06.502  5864  9421 W RequestThread-0:       at android.os.HandlerThread.run(HandlerThread.java:65)

11-27 14:30:06.505  5864  9421 E RequestThread-0: Received device exception: 
11-27 14:30:06.505  5864  9421 E RequestThread-0: java.lang.RuntimeException: getParameters failed (empty parameters)
11-27 14:30:06.505  5864  9421 E RequestThread-0:       at android.hardware.Camera.native_getParameters(Native Method)
11-27 14:30:06.505  5864  9421 E RequestThread-0:       at android.hardware.Camera.getParameters(Camera.java:1986)
11-27 14:30:06.505  5864  9421 E RequestThread-0:       at android.hardware.camera2.legacy.RequestThreadManager.configureOutputs(RequestThreadManager.java:429)
11-27 14:30:06.505  5864  9421 E RequestThread-0:       at android.hardware.camera2.legacy.RequestThreadManager.-wrap0(Unknown Source:0)
11-27 14:30:06.505  5864  9421 E RequestThread-0:       at android.hardware.camera2.legacy.RequestThreadManager$5.handleMessage(RequestThreadManager.java:721)
11-27 14:30:06.505  5864  9421 E RequestThread-0:       at android.os.Handler.dispatchMessage(Handler.java:102)
11-27 14:30:06.505  5864  9421 E RequestThread-0:       at android.os.Looper.loop(Looper.java:164)
11-27 14:30:06.505  5864  9421 E RequestThread-0:       at android.os.HandlerThread.run(HandlerThread.java:65)
11-27 14:30:06.505  5864  9399 I CameraDeviceState: Legacy camera service transitioning to state IDLE
11-27 14:30:06.505  5864  9399 E CameraDeviceState: Cannot call idle while in state: 0
11-27 14:30:06.506  5864  5984 I CameraDevices: Camera #0: Unavailable!
11-27 14:30:06.507  5864  5864 D Surface : Surface::setBuffersUserDimensions(this=0x77efdd2000,w=1280,h=720)
11-27 14:30:06.507  5864  5864 I CameraDeviceState: Legacy camera service transitioning to state CONFIGURING

11-27 14:30:06.508  5864  5864 E CameraDeviceState: Cannot call configure while in state: 0

11-27 14:30:06.510  5864  9399 I CreateCaptureSession: Camera 0: Capture Session #1002 configured!

11-27 14:30:06.511  5864  9399 I CameraManager: Camera 0: Disconnected!

11-27 14:30:06.514  5864  9399 E CameraSession: Camera Device android.hardware.camera2.impl.CameraDeviceImpl@df42232 has been disconnected!
11-27 14:30:06.514  5864  9399 E CameraSession: com.mrousavy.camera.core.CameraDisconnectedError: [session/camera-has-been-disconnected] The given Camera device (id: 0) has been disconnected! Error: DISCONNECTED
11-27 14:30:06.514  5864  9399 E CameraSession:         at com.mrousavy.camera.extensions.CameraManager_openCameraKt$openCamera$2$callback$1.onDisconnected(CameraManager+openCamera.kt:38)
11-27 14:30:06.514  5864  9399 E CameraSession:         at android.hardware.camera2.impl.CameraDeviceImpl$7.run(CameraDeviceImpl.java:235)
11-27 14:30:06.514  5864  9399 E CameraSession:         at android.os.Handler.handleCallback(Handler.java:790)
11-27 14:30:06.514  5864  9399 E CameraSession:         at android.os.Handler.dispatchMessage(Handler.java:99)
11-27 14:30:06.514  5864  9399 E CameraSession:         at android.os.Looper.loop(Looper.java:164)
11-27 14:30:06.514  5864  9399 E CameraSession:         at android.os.HandlerThread.run(HandlerThread.java:65)

11-27 14:30:06.514  5864  9399 E CameraView: invokeOnError(...):
11-27 14:30:06.515  5864  9399 W System.err: com.mrousavy.camera.core.CameraDisconnectedError: [session/camera-has-been-disconnected] The given Camera device (id: 0) has been disconnected! Error: DISCONNECTED

11-27 14:30:06.515  5864  9399 W System.err:    at com.mrousavy.camera.extensions.CameraManager_openCameraKt$openCamera$2$callback$1.onDisconnected(CameraManager+openCamera.kt:38)
11-27 14:30:06.515  5864  9399 W System.err:    at android.hardware.camera2.impl.CameraDeviceImpl$7.run(CameraDeviceImpl.java:235)
11-27 14:30:06.515  5864  9399 W System.err:    at android.os.Handler.handleCallback(Handler.java:790)
11-27 14:30:06.515  5864  9399 W System.err:    at android.os.Handler.dispatchMessage(Handler.java:99)
11-27 14:30:06.516  5864  5864 I CameraSession: Successfully configured Session with 1 outputs for Camera #0!
11-27 14:30:06.516  5864  5864 W CameraSession: Preview Output is null, aborting...
11-27 14:30:06.516  5864  5864 I CameraSession: Successfully updated CameraSession Configuration! isActive: true

11-27 14:30:06.517  5864  9399 W System.err:    at android.os.Looper.loop(Looper.java:164)
11-27 14:30:06.517  5864  9399 W System.err:    at android.os.HandlerThread.run(HandlerThread.java:65)

11-27 14:30:06.521  5864  9427 D Surface : Surface::disconnect(this=0x77f0449000,api=1)

11-27 14:30:06.525  5864  9427 W libEGL  : EGLNativeWindowType 0x77f0449010 disconnect failed

11-27 14:30:06.530  5864  9427 E Legacy-CameraDevice-JNI: getNativeWindow: Surface had no valid native window.

11-27 14:30:06.531  5864  9427 I BufferQueueConsumer: [SurfaceTexture-1-5864-3](this:0x77e9cd4000,id:5,api:4,p:-1,c:-1) disconnect(C)

11-27 14:30:06.538  5864  9512 D Camera-JNI: (tid:9512)[~MtkJNICameraContext] this:0x77f22e3ba0 

11-27 14:30:06.539  5864  9399 I CreateCaptureSession: Camera 0: Capture Session #1002 closed!
11-27 14:30:06.539  5864  9399 I CameraSession: Camera Session android.hardware.camera2.impl.CameraCaptureSessionImpl@1343100 has been closed!

11-27 14:30:06.543  5864  5864 D TSBackgroundFetch: ā˜Æļø  onPause

11-27 14:30:06.648  5864  5983 I ReactNativeJS: ISINACTIVE

11-27 14:30:06.810  5864  5864 D TSBackgroundFetch: ā˜Æļø  onStop

11-27 14:30:06.816  5864  5864 V PhoneWindow: DecorView setVisiblity: visibility = 4, Parent = ViewRoot{e9db12b de.xtl.kurier/de.xtl.kurier.MainActivity,ident = 1}, this = DecorView@3a23f9c[MainActivity]

11-27 14:30:07.182  5864  5983 I ReactNativeJS: HOMESCREEN: Switched from active to background. Intent: CAMERA

11-27 14:30:07.529  5864  5864 I CameraView: Updating CameraSession...

11-27 14:30:07.530  5864  9399 I CameraSession: Updating CameraSession Configuration...

11-27 14:30:07.534  5864  9399 E CameraSession: Failed to configure CameraSession! Error: Session has been closed; further changes are illegal., Config-Diff: Difference(deviceChanged=false, outputsChanged=false, sidePropsChanged=true)
11-27 14:30:07.534  5864  9399 E CameraSession: java.lang.IllegalStateException: Session has been closed; further changes are illegal.
11-27 14:30:07.534  5864  9399 E CameraSession:         at android.hardware.camera2.impl.CameraCaptureSessionImpl.checkNotClosed(CameraCaptureSessionImpl.java:671)
11-27 14:30:07.534  5864  9399 E CameraSession:         at android.hardware.camera2.impl.CameraCaptureSessionImpl.stopRepeating(CameraCaptureSessionImpl.java:284)
11-27 14:30:07.534  5864  9399 E CameraSession:         at com.mrousavy.camera.core.CameraSession.configureCaptureRequest(CameraSession.kt:371)
11-27 14:30:07.534  5864  9399 E CameraSession:         at com.mrousavy.camera.core.CameraSession.configure(CameraSession.kt:141)
11-27 14:30:07.534  5864  9399 E CameraSession:         at com.mrousavy.camera.CameraView$update$1.invokeSuspend(CameraView.kt:143)
11-27 14:30:07.534  5864  9399 E CameraSession:         at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
11-27 14:30:07.534  5864  9399 E CameraSession:         at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
11-27 14:30:07.534  5864  9399 E CameraSession:         at android.os.Handler.handleCallback(Handler.java:790)
11-27 14:30:07.534  5864  9399 E CameraSession:         at android.os.Handler.dispatchMessage(Handler.java:99)
11-27 14:30:07.534  5864  9399 E CameraSession:         at android.os.Looper.loop(Looper.java:164)
11-27 14:30:07.534  5864  9399 E CameraSession:         at android.os.HandlerThread.run(HandlerThread.java:65)
11-27 14:30:07.534  5864  9399 E CameraView: invokeOnError(...):
11-27 14:30:07.534  5864  9399 W System.err: java.lang.IllegalStateException: Session has been closed; further changes are illegal.
11-27 14:30:07.534  5864  9399 W System.err:    at android.hardware.camera2.impl.CameraCaptureSessionImpl.checkNotClosed(CameraCaptureSessionImpl.java:671)
11-27 14:30:07.535  5864  9399 W System.err:    at android.hardware.camera2.impl.CameraCaptureSessionImpl.stopRepeating(CameraCaptureSessionImpl.java:284)
11-27 14:30:07.535  5864  9399 W System.err:    at com.mrousavy.camera.core.CameraSession.configureCaptureRequest(CameraSession.kt:371)
11-27 14:30:07.535  5864  9399 W System.err:    at com.mrousavy.camera.core.CameraSession.configure(CameraSession.kt:141)
11-27 14:30:07.535  5864  9399 W System.err:    at com.mrousavy.camera.CameraView$update$1.invokeSuspend(CameraView.kt:143)

11-27 14:30:07.535  5864  9399 W System.err:    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
11-27 14:30:07.535  5864  9399 W System.err:    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
11-27 14:30:07.536  5864  9399 W System.err:    at android.os.Handler.handleCallback(Handler.java:790)
11-27 14:30:07.536  5864  9399 W System.err:    at android.os.Handler.dispatchMessage(Handler.java:99)
11-27 14:30:07.536  5864  9399 W System.err:    at android.os.Looper.loop(Looper.java:164)

11-27 14:30:07.536  5864  9399 W System.err:    at android.os.HandlerThread.run(HandlerThread.java:65)

11-27 14:30:07.542  5864  5864 I CameraSession: Destroying session..
11-27 14:30:07.545  5864  5864 D AndroidRuntime: Shutting down VM

--------- beginning of crash
11-27 14:30:07.549  5864  5864 E AndroidRuntime: FATAL EXCEPTION: main
11-27 14:30:07.549  5864  5864 E AndroidRuntime: Process: de.xtl.kurier, PID: 5864
11-27 14:30:07.549  5864  5864 E AndroidRuntime: java.lang.IllegalStateException: Session has been closed; further changes are illegal.
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at android.hardware.camera2.impl.CameraCaptureSessionImpl.checkNotClosed(CameraCaptureSessionImpl.java:671)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at android.hardware.camera2.impl.CameraCaptureSessionImpl.stopRepeating(CameraCaptureSessionImpl.java:284)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at com.mrousavy.camera.core.CameraSession.destroy(CameraSession.kt:160)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at com.mrousavy.camera.core.CameraSession.access$destroy(CameraSession.kt:58)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at com.mrousavy.camera.core.CameraSession$close$1.invokeSuspend(CameraSession.kt:102)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:284)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source:1)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source:1)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at com.mrousavy.camera.core.CameraSession.close(CameraSession.kt:100)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at com.mrousavy.camera.CameraView.destroy(CameraView.kt:136)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at com.mrousavy.camera.CameraViewManager.onDropViewInstance(CameraViewManager.kt:35)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at com.mrousavy.camera.CameraViewManager.onDropViewInstance(CameraViewManager.kt:15)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at com.facebook.react.uimanager.NativeViewHierarchyManager.dropView(NativeViewHierarchyManager.java:635)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at com.swmansion.reanimated.layoutReanimation.ReanimatedNativeHierarchyManager.dropView(ReanimatedNativeHierarchyManager.java:399)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at com.facebook.react.uimanager.NativeViewHierarchyManager.dropView(NativeViewHierarchyManager.java:646)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at com.swmansion.reanimated.layoutReanimation.ReanimatedNativeHierarchyManager.dropView(ReanimatedNativeHierarchyManager.java:399)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at com.facebook.react.uimanager.NativeViewHierarchyManager.manageChildren(NativeViewHierarchyManager.java:499)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at com.swmansion.reanimated.layoutReanimation.ReanimatedNativeHierarchyManager.manageChildren(ReanimatedNativeHierarchyManager.java:300)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at com.facebook.react.uimanager.UIViewOperationQueue$ManageChildrenOperation.execute(UIViewOperationQueue.java:217)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at com.facebook.react.uimanager.UIViewOperationQueue$1.run(UIViewOperationQueue.java:915)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches(UIViewOperationQueue.java:1026)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at com.facebook.react.uimanager.UIViewOperationQueue.-$$Nest$mflushPendingBatches(Unknown Source:0)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at com.facebook.react.uimanager.UIViewOperationQueue$2.runGuarded(UIViewOperationQueue.java:984)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at com.facebook.react.bridge.GuardedRunnable.run(GuardedRunnable.java:30)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at android.os.Handler.handleCallback(Handler.java:790)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:99)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:164)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:6523)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
11-27 14:30:07.549  5864  5864 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857)

Camera Device

{
  "sensorOrientation": "landscape-right",
  "hardwareLevel": "legacy",
  "maxZoom": 4,
  "minZoom": 1,
  "supportsLowLightBoost": false,
  "neutralZoom": 1,
  "physicalDevices": [
    "wide-angle-camera"
  ],
  "supportsFocus": true,
  "supportsRawCapture": false,
  "isMultiCam": false,
  "name": "BACK (0)",
  "hasFlash": true,
  "hasTorch": true,
  "position": "back",
  "id": "0"
}

Device

Multiple devices

VisionCamera Version

3.1.x

Can you reproduce this issue in the VisionCamera Example app?

I didn't try (āš ļø your issue might get ignored & closed if you don't try this)

Additional information

xtl-geiger commented 11 months ago

The cause was conditional rendering of a parent component, while putting the app into the background.

xtl-geiger commented 11 months ago

My bad, it is still happening, but not every time.

spsaucier commented 11 months ago

In the case I have recorded, the reported issue occurred six seconds after a camera-has-been-disconnected error:

Camera.onError(session/camera-has-been-disconnected): [session/camera-has-been-disconnected] The given Camera device (id: 0) has been disconnected! Error: DISCONNECTED [session/camera-has-been-disconnected]: [session/camera-has-been-disconnected] The given Camera device (id: 0) has been disconnected! Error: DISCONNECTED
{
arguments: [
Camera.onError(session/camera-has-been-disconnected): [session/camera-has-been-disconnected] The given Camera device (id: 0) has been disconnected! Error: DISCONNECTED, 
{
_code: session/camera-has-been-disconnected, 
_message: [session/camera-has-been-disconnected] The given Camera device (id: 0) has been disconnected! Error: DISCONNECTED, 
message: [session/camera-has-been-disconnected] The given Camera device (id: 0) has been disconnected! Error: DISCONNECTED, 
name: session/camera-has-been-disconnected, 
stack: 
[session/camera-has-been-disconnected]: [session/camera-has-been-disconnected] The given Camera device (id: 0) has been disconnected! Error: DISCONNECTED
    at construct (native)
    at Wrapper (address at index.android.bundle:1:445833)
    at construct (native)
    at _createSuperInternal (address at index.android.bundle:1:11391081)
    at call (native)
    at CameraError (address at index.android.bundle:1:11391557)
    at construct (native)
    at _createSuperInternal (address at index.android.bundle:1:11391081)
    at apply (native)
    at CameraRuntimeError (address at index.android.bundle:1:11392061)
    at onError (address at index.android.bundle:1:11388929)
    at apply (native)
    at invokeGuardedCallbackImpl (address at index.android.bundle:1:577433)
    at apply (native)
    at invokeGuardedCallback (address at index.android.bundle:1:577490)
    at apply (native)
    at invokeGuardedCallbackAndCatchFirstError (address at index.android.bundle:1:577522)
    at executeDispatch (address at index.android.bundle:1:577654)
    at executeDispatchesAndReleaseTopLevel (address at index.android.bundle:1:581911)
    at call (native)
    at forEachAccumulated (address at index.android.bundle:1:579137)
    at anonymous (address at index.android.bundle:1:582263)
    at batchedUpdatesImpl (address at index.android.bundle:1:641456)
    at batchedUpdates (address at index.android.bundle:1:581831)
    at _receiveRootNodeIDEvent (address at index.android.bundle:1:582104)
    at receiveEvent (address at index.android.bundle:1:635961)
    at apply (...
}
]
}
tahaipek commented 11 months ago

Do you have any suggestions or workarounds for a solution?

mrousavy commented 10 months ago

Hey! Thanks for reporting this issue.

I've been working the past days on making sure the Camera lifecycle is safely handled and released when needed to make sure this crash doesn't occur anymore.

I just created a PR for this - can you please this to see if that fixes the issue for you? https://github.com/mrousavy/react-native-vision-camera/pull/2339

If this fixes your issue, please consider šŸ’– sponsoring me on GitHub šŸ’– to support me / thank me for building VisionCamera and continuously improving it.

If this does not fix your issue, please clone the repo, check out the branch fix/blackscreen (the PR above), run the Example app, reproduce your issue there and share the adb logcat logs with me (upload to pastebin or gist) so I can investigate this further.

Thank you! šŸ™