Expo crash after <Camera> mounts (sometimes) [iOS]
See original GitHub issue🐛 Bug Report
Environment
Diagnostics:
Expo CLI 2.11.6 environment info:
System:
OS: macOS 10.14.3
Shell: 5.3 - /bin/zsh
Binaries:
Node: 8.15.0 - /usr/local/opt/node@8/bin/node
Yarn: 1.13.0 - /usr/local/bin/yarn
npm: 6.4.1 - /usr/local/opt/node@8/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
IDEs:
Xcode: 10.2/10E125 - /usr/bin/xcodebuild
npmPackages:
@storybook/react-native: ^4.1.7 => 4.1.11
expo: ^32.0.6 => 32.0.6
react: 16.5.0 => 16.5.0
react-native: https://github.com/expo/react-native/archive/sdk-32.0.2.tar.gz => 0.57.1
react-navigation: ^3.5.1 => 3.5.1
App target: iOS app for iPad, not ejected. Issue reproducible with the IPA file and with the Expo client, as well as in the simulator.
I have local stacktraces generated from my actual application, let me know if you need them.
Steps to Reproduce
I have an app using react-navigation and the Camera component. When opening the app and pressing a button, we navigate to a second screen with more or less the Camera example from the docs. It works fine - I am scanning a QR code. When going back (camera screen unmounts) and on this screen again a couple times, the app will crash entirely (Expo closes). This sometimes happen on the first mount as well.
The error message is the following:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVCaptureSession addOutput:] Cannot add output <AVCaptureMetadataOutput: 0x28225f6c0> to capture session <AVCaptureSession: 0x2820f40c0 [AVCaptureSessionPresetHigh]> because more than one output of the same type is unsupported'
Expected Behavior
The app never crashes 😉
Actual Behavior
Random crash when trying to actually mount the <Camera> element.
Reproducible Demo
I was able to reproduce the issue on a fresh base: https://github.com/MickaelBergem/bug-repro-camera-crash. I usually need to repeat the unmount/mount cycle by navigating back and forth at least 10 times before the app crashes.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:11 (5 by maintainers)
I have been trying to figure out a similar bug for a while. Expo/App Store app was crashing with no stack trace. I was experiencing this on iOS 12.1+. I was passing barCodeScannerSettings something like { barCodeTypes: [BarCodeScanner.Constants.BarCodeType.code39, BarCodeScanner.Constants.BarCodeType.code39mod43] }}. I even tried { barCodeTypes: [] }}. I still experienced the crash. I found to resolve my issue was to remove prop barCodeScannerSettings altogether. Haven’t experienced it again. Hope this helps!
@NathanBeesley you just saved my day!! Thanks a lot.
I just tested it on the reproduction case, and it’s no longer crashing. I confirm this workaround works.