expo: [expo-camera/next 14.1.*] Expo Go app crashes when opening Camera

Minimal reproducible example

https://github.com/the-devbear/expo-camera-next-mre

What platform(s) does this occur on?

iOS

Did you reproduce this issue in a development build?

Yes

Summary

Hello, I’m using an IPhone 12 with expo Go and wanted to use the barcode scanner. Since the BarcodeScanner package redirects to expo-camera/next I wanted to use this instead. But unfortunately the expo go crashes as soon as I trie to open the camera. It only crashes when I’m using CameraView and not Camera. It also works on the version 14.0.6. Unfortunately I don’t get any error message in the terminal were I ran the build it just crashes… So please let me know, how I can provide more Information.

Video 1: version 14.1.1

https://github.com/expo/expo/assets/104125178/83d235c6-2180-4f29-8635-571c9664facb

Video 2: version 14.0.6

https://github.com/expo/expo/assets/104125178/8307d568-66b1-4255-9fa8-7ac2ec9441b7

If I can help in any other way please let me know.

Environment

expo-env-info 1.2.0 environment info:
    System:
      OS: macOS 14.1.2
      Shell: 5.9 - /bin/zsh
    Binaries:
      Node: 20.12.0 - ~/.nvm/versions/node/v20.12.0/bin/node
      Yarn: 1.22.19 - /opt/homebrew/bin/yarn
      npm: 10.5.0 - ~/.nvm/versions/node/v20.12.0/bin/npm
    Managers:
      CocoaPods: 1.14.3 - /opt/homebrew/bin/pod
    SDKs:
      iOS SDK:
        Platforms: DriverKit 23.0, iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0
    IDEs:
      Xcode: 15.0/15A240d - /usr/bin/xcodebuild
    npmPackages:
      expo: ~50.0.14 => 50.0.14
      react: 18.2.0 => 18.2.0
      react-native: 0.73.6 => 0.73.6
    npmGlobalPackages:
      eas-cli: 7.6.2
    Expo Workflow: managed

Expo Doctor Diagnostics

npx expo-doctor@latest
Need to install the following packages:
expo-doctor@1.5.0
Ok to proceed? (y) y
✔ Check Expo config for common issues
✔ Check package.json for common issues
✔ Check dependencies for packages that should not be installed directly
✔ Check for common project setup issues
✔ Check for issues with metro config
✔ Check npm/ yarn versions
✔ Check Expo config (app.json/ app.config.js) schema
✔ Check for legacy global CLI installed locally
✔ Check native tooling versions
✔ Check that native modules do not use incompatible support packages
✔ Check that native modules use compatible support package versions for installed Expo SDK
✔ Check that packages match versions required by installed Expo SDK

Didn't find any issues with the project!

About this issue

  • Original URL
  • State: closed
  • Created 3 months ago
  • Reactions: 5
  • Comments: 23 (1 by maintainers)

Most upvoted comments

This should be resolved in 14.1.3

I am also seeing this; like @the-devbear, 14.0.6 works whereas 14.1.2 crashes. This is happening for us in our development builds.

I’m also still having this issue even tho I have set the mute prop to true.

These are the crash logs copied from Xcode.

*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** -[AVCaptureSession startRunning] startRunning may not be called between calls to beginConfiguration and commitConfiguration' *** First throw call stack: (0x18ddeab28 0x185c5ef78 0x1aac18e1c 0x102810bcc 0x10280168c 0x195bfadd4 0x195bfe2d8 0x195c121c8 0x195c10d8c 0x195c02284 0x195c02f30 0x195c0dcb4 0x195c0d528 0x1e9ce0f20 0x1e9ce0fc0)

I have the same issue as @the-devbear. In my tests I found out, that the camera shows a black screen if the app has no permissions for the camera functionality but does not crash. If it does have permissions, it crashes instantly.

@alanjhughes

I had the same issue as shown on the video from OP, but using Development Builds. I bumped the version to 14.1.3, but as the two previous comments it doesn’t resolve it for me.

I even tried using yarn as suggested here: https://github.com/expo/expo/issues/27410

The Console shows:

*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** -[AVCaptureSession startRunning] startRunning may not be called between calls to beginConfiguration and commitConfiguration'
*** First throw call stack:
(0x1a294eb28 0x19a7caf78 0x1bf77ce1c 0x10505fec4 0x105023b30 0x1aa75edd4 0x1aa7622d8 0x1aa7761c8 0x1aa774d8c 0x1aa766284 0x1aa766f30 0x1aa771cb4 0x1aa771528 0x1fe844f20 0x1fe844fc0)

While debugging I decided to switch to Expo Go, which I don’t generally use anymore and the camera started working again. What could be the reason for the difference?

@andrewbeckman I installed 14.1.3 which hasn’t solved the issue unfortunately…App crashed when request permissions on video (both camera and microphone.

thanks for your regards

I am using expo-camera/next@14.1.1 for barcode scanning only, so microphone is naturally NOT needed. I’ve added the mute prop to the CameraView and no microphonePermission or NSMicrophoneUsageDescription to app config. Now I am not getting the microphone permissions prompt - just as expected. I am however still getting the NSGenericException error every time I start the camera, together with an app crash. I have granted permissions to use the camera.

I tried do downgrade to 14.0.6, and this caused me to only get the error the first time, directly after granting permissions. Subsequent times when I opened the camera it ran smoothly.

I also tried to upgrade to 14.1.2 In hopes of some fix that would affect this but it acts the same as 14.1.1 (i.e. camera crashes every time after granting camera permission)

I looked into the error message in my logging tool and noticed that the error occurs in two different functions: the public func onAppForegrounded and the private func startSession, both in CameraViewNext in expo/packages/expo-camera/ios/Next/CameraViewNext.swift.

There seems to be a delay in startSession:

...
self.addErrorNotification()
self.changePreviewOrientation()
self.session.commitConfiguration()

// Delay starting the scanner
self.sessionQueue.asyncAfter(deadline: .now() + 0.5) {
  self.barcodeScanner.maybeStartBarcodeScanning()
  if !self.session.isRunning {
    self.session.startRunning()
  }
  self.onCameraReady()
}

...

async/await in swift is beyond my expertise, but it looks to me as if the delay is added to allow for commitConfiguration to complete instead of actually awaiting it or having some form of callback. Seems relevant since the error message states that ... startRunning may not be called between calls to beginConfiguration and commitConfiguration'.

Does it imply that startRunning is called before commitConfiguration is called or before it is completed?

If the first is true and startRunning is called before commitConfiguration is called then perhaps it is called by another async function in parallel? addErrorNotification is called just two lines above commitConfiguration in the code block from the startSession func pasted above, and startRunning is indeed called inside addErrorNotification. Given async nature and the right timing then the startRunning call in addErrorNotification could trigger before commitConfiguration in startSession.

The old/legacy expo-camera Camera view swift class does not do things the same way. It doesn’t run commitConfiguration prior to startRunning, but does this instead:


...
self.addErrorNotification()
self.changePreviewOrientation()

self.sessionQueue.asyncAfter(deadline: .now() + round(50 / 1_000_000)) {
  self.maybeStartFaceDetection(self.presetCamera != .back)
  if let barCodeScanner = self.barCodeScanner {
    barCodeScanner.maybeStartBarCodeScanning()
  }

  self.session.startRunning()
  self.ensureSessionConfiguration() // <-- ensureSessionConfiguration is used here but not in expo-camera/next
  self.onCameraReady()
}

...

These are just my observations, but I know nothing about swift so… Hopefully someone more knowledgeable can see exactly what needs to be done here.

I’ve reverted to “expo-camera”: “14.0.6”, and all works as excepted

same here, same error when crash, but I found it just randomly happen, sometimes it works, sometimes it crash instantly after allow permission

I have the same issue.

Had a look at their solution to set the mute prop to true, but this did not resolve the issue. Unfortunately for me, the application still crashes every time the camera is accessed. 😢

Same issue encountared on a development build.

  • Version: 14.1.2
  • Camera Permission: enabled

I was able to getting an error message:

*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** -[AVCaptureSession startRunning] startRunning may not be called between calls to beginConfiguration and commitConfiguration'
*** First throw call stack:
(0x188fca678 0x181277c80 0x1a56a9e00 0x104cb0ff0 0x100fa5a00 0x100f6a4a4 0x10526eb34 0x105271c20 0x105289078 0x105287acc 0x1052767c4 0x105277728 0x1052845f8 0x105283c2c 0x1f2fd3964 0x1f2fd3a04)
DevLauncher tries to handle uncaught exception: *** -[AVCaptureSession startRunning] startRunning may not be called between calls to beginConfiguration and commitConfiguration
Stack Trace: (
    "0   CoreFoundation                      0x0000000188fca684 5A6C1F41-BF70-32F6-A1D6-5B894DD21362 + 968324",
    "1   libobjc.A.dylib                     0x0000000181277c80 objc_exception_throw + 60",
    "2   AVFCapture                          0x00000001a56a9e00 3F43BF8F-9C34-3B81-8502-8A74EC9647A8 + 171520",
    "3   libRPAC.dylib                       0x0000000104cb0ff0 _replacement_AVCaptureSession_startRunning + 108",
    "4   expocameranextmre                   0x0000000100fa5a00 $s10ExpoCamera0B8ViewNextC12startSession33_0C10F0D99CA71488C42A4C34CA4B3A30LLyyFyyYbcfU_yyYbcfU_ + 132",
    "5   expocameranextmre                   0x0000000100f6a4a4 $sIegh_IeyBh_TR + 48",
    "6   libdispatch.dylib                   0x000000010526eb34 _dispatch_client_callout + 20",
    "7   libdispatch.dylib                   0x0000000105271c20 _dispatch_continuation_pop + 676",
    "8   libdispatch.dylib                   0x0000000105289078 _dispatch_source_latch_and_call + 480",
    "9   libdispatch.d
Task <913FC668-CAC2-4E60-90E2-199508759FA8>.<3> HTTP load failed, 736/0 bytes (error code: 18.446.744.073.709.550.611 [4:18.446.744.073.709.551.612])
libc++abi: terminating due to uncaught exception of type NSException