react-native-vision-camera: ๐Ÿ› App Crashes When Navigating Back to Camera Screen

Whatโ€™s happening?

The app crashes when I navigate back from the camera screen and then attempt to return to the camera screen.

Steps to Reproduce:

  1. Navigate to the camera screen within the app.
  2. Interact with the camera screen as needed.
  3. Use the appโ€™s navigation to go back to the previous screen.
  4. Navigate back to the camera screen.

Error:

java.lang.IllegalArgumentException: Surface was abandoned

Reproduceable Code

function App() {

  const codeScanner = useCodeScanner({
    codeTypes: ['qr', 'ean-13'],
    onCodeScanned: console.log,
  });

  const device = useCameraDevice('back', {
    physicalDevices: ['wide-angle-camera'],
  });

  if (device == null) return null;
  return (
    <Camera
      style={StyleSheet.absoluteFill}
      device={device}
      isActive={true}
      enableZoomGesture
        focusable
      codeScanner={codeScanner}
    />
  )
}

Relevant log output

10-12 15:20:57.082  9477 10289 E AndroidRuntime: FATAL EXCEPTION: mrousavy/VisionCamera.main
10-12 15:20:57.082  9477 10289 E AndroidRuntime: Process: com.dt.johnny.jdtmelhu, PID: 9477
10-12 15:20:57.082  9477 10289 E AndroidRuntime: java.lang.IllegalArgumentException: Surface was abandoned
10-12 15:20:57.082  9477 10289 E AndroidRuntime: 	at android.hardware.camera2.utils.SurfaceUtils.getSurfaceSize(SurfaceUtils.java:135)
10-12 15:20:57.082  9477 10289 E AndroidRuntime: 	at android.hardware.camera2.params.OutputConfiguration.<init>(OutputConfiguration.java:563)
10-12 15:20:57.082  9477 10289 E AndroidRuntime: 	at android.hardware.camera2.params.OutputConfiguration.<init>(OutputConfiguration.java:345)
10-12 15:20:57.082  9477 10289 E AndroidRuntime: 	at com.mrousavy.camera.core.outputs.SurfaceOutput.toOutputConfiguration(SurfaceOutput.kt:38)
10-12 15:20:57.082  9477 10289 E AndroidRuntime: 	at com.mrousavy.camera.extensions.CameraDevice_createCaptureSessionKt.createCaptureSession(CameraDevice+createCaptureSession.kt:57)
10-12 15:20:57.082  9477 10289 E AndroidRuntime: 	at com.mrousavy.camera.core.CameraSession.getCaptureSession(CameraSession.kt:438)
10-12 15:20:57.082  9477 10289 E AndroidRuntime: 	at com.mrousavy.camera.core.CameraSession.startRunning(CameraSession.kt:532)
10-12 15:20:57.082  9477 10289 E AndroidRuntime: 	at com.mrousavy.camera.core.CameraSession.access$startRunning(CameraSession.kt:49)
10-12 15:20:57.082  9477 10289 E AndroidRuntime: 	at com.mrousavy.camera.core.CameraSession$startRunning$1.invokeSuspend(Unknown Source:14)
10-12 15:20:57.082  9477 10289 E AndroidRuntime: 	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
10-12 15:20:57.082  9477 10289 E AndroidRuntime: 	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
10-12 15:20:57.082  9477 10289 E AndroidRuntime: 	at android.os.Handler.handleCallback(Handler.java:958)
10-12 15:20:57.082  9477 10289 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:99)
10-12 15:20:57.082  9477 10289 E AndroidRuntime: 	at android.os.Looper.loopOnce(Looper.java:205)
10-12 15:20:57.082  9477 10289 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:294)
10-12 15:20:57.082  9477 10289 E AndroidRuntime: 	at android.os.HandlerThread.run(HandlerThread.java:67)
10-12 15:20:57.082  9477 10289 E AndroidRuntime: 	Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@9a35690, mrousavy/VisionCamera.main]

Camera Device

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

Device

Any Android Devices

VisionCamera Version

3.3.1

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

About this issue

  • Original URL
  • State: closed
  • Created 9 months ago
  • Reactions: 9
  • Comments: 16 (5 by maintainers)

Most upvoted comments

Yea basically I need to do a refactor on the Codebase - I now know exactly what I need for the session configuration, and need to do all of this fully atomically.

I just fixed this in #2049, and released it to npm (v3.6.0) ๐ŸŽ‰

If you appreciate my work and dedication to fix your issues and make VisionCamera better, please ๐Ÿ’– consider sponsoring me on GitHub ๐Ÿ’– to say thanks. Thanks!

i think i can fix this in #2049