react-native-vision-camera: 🐛 iOS 17.0.2 (iPhone 15) crashing on camera load
What’s happening?
While loading camera seems like AVCaptureColorSpace
throws the following error
Fatal error: AVCaptureDevice.Position has unknown state.
- Could it be new formats in new iPhone or is this a bug?
- Is removing this error a good workaround for the time being?
- Could
Reproduceable Code
const device = cameraDevices.back;
const format = useMemo(() => {
if (!device?.formats) return undefined;
const sortedFormats = device.formats.sort(sortFormats);
const formatsWith60FPS = sortedFormats.filter((f) =>
f.frameRateRanges.some((r) => frameRateIncluded(r, 60))
);
if (formatsWith60FPS.length > 0) return formatsWith60FPS[1];
if (sortedFormats.length > 0) return sortedFormats[0];
return undefined;
}, [device?.formats]);
const fps = useMemo(() => {
if (!format) return undefined;
return Math.max(
...format.frameRateRanges.map((range) => range.maxFrameRate)
);
}, [format]);
<ReanimatedCamera
photo={true}
video={false}
device={device}
enableHighQualityPhotos={true}
enableZoomGesture={false}
orientation="portrait"
isActive={focused}
style={{
position: 'absolute',
height: '100%',
width: '100%',
padding: 0,
margin: 0,
}}
ref={camera}
torch={torch}
format={Platform.OS === 'android' ? undefined : format}
preset={!format || Platform.OS === 'android' ? 'photo' : undefined}
fps={Platform.OS === 'android' ? undefined : fps}
hdr={Platform.OS === 'android' ? undefined : false}
animatedProps={cameraAnimatedProps}
onInitialized={() => setCameraReady(true)}
onError={(err) => {
console.error(err);
}}
/>;
Relevant log output
VisionCamera/AVCaptureColorSpace+descriptor.swift:41: Fatal error: AVCaptureDevice.Position has unknown state.
Camera Device
Unknown as I have don't have the new iPhone and this is a crash report
Device
ex. iPhone 15
VisionCamera Version
2.15.6
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
- I am using Expo
- I have enabled Frame Processors (react-native-worklets-core)
- I have read the Troubleshooting Guide
- I agree to follow this project’s Code of Conduct
- I searched for similar issues in this repository and found none.
About this issue
- Original URL
- State: closed
- Created 9 months ago
- Reactions: 20
- Comments: 43 (4 by maintainers)
Commits related to this issue
- handle iPhone 15 / iOS17 according to https://github.com/mrousavy/react-native-vision-camera/issues/1840#issuecomment-1732360337 — committed to Sidebook/react-native-vision-camera by Sidebook 9 months ago
- fix(IT Wallet): [SIW-558] Fix camera crash on iPhone 15 (#5048) ## Short description This PR adds [this proposed patch](https://github.com/mrousavy/react-native-vision-camera/issues/1840#issuecomme... — committed to pagopa/io-app by LazyAfternoons 9 months ago
- fix(IT Wallet): [SIW-558] Fix camera crash on iPhone 15 (#5048) ## Short description This PR adds [this proposed patch](https://github.com/mrousavy/react-native-vision-camera/issues/1840#issuecomme... — committed to pagopa/io-app by LazyAfternoons 9 months ago
- fix: Fix "Fatal error: AVCaptureDevice.Position has unknown state" * fixes #1840 — committed to mrousavy/react-native-vision-camera by mrousavy 9 months ago
Fixed in latest v2
Just released this in 2.16.2., hopefully with a better and more stable solution. Also the crash in colorSpace is fixed.
If you appreciate my free support for VisionCamera, please consider sponsoring me on GitHub. Thanks. ❤️
This patch temporarily resolves the issue by removing
colorSpaces
fromAVCaptureDevice.Format
.Oh right, apparently this field is removed in v3 as well so upgrading might resolve this as well if that’s an option until the new value is figured out.
https://developer.apple.com/documentation/avfoundation/avcapturecolorspace
iPhone 15 Pro, Hope this help.
Upgrade to V3.
Looks like this is the new enum value they’ve added: https://developer.apple.com/documentation/avfoundation/avcapturecolorspace/applelog
I suppose adding support for this requires building the app with xcode 15 / ios 17 SDK.
I think it’ll be released in
2.16.2
, but not yet now https://github.com/mrousavy/react-native-vision-camera/commits/v2Xcode 15, camera screen crashes with
Property '__scanCodes' doesn't exist
. The previous build (2.15.5) works fine but doesn’t work with code 15.react-native-vision-camera version 2.16.2 react-native-reanimated version 3.5.4
Hi @mrousavy
I am still using V2 2.15.6 because by the time I implemented it 2.16.1 didn’t have support for frameProcessors.
I am getting the app crashing for iOS 17+. Does 2.16.2 has support for frameProcessors? Or what would you suggest in this case?
We are having the same issue. We are still using react-native-camera and not react-native-vision-camera. I am guessing if we upgrade to the latest react-native-vision-camera that will solve this. We are going to give that a try in the am. Has anyone else had the issue of the camera going black on an older phone, but on iOS17?
Could a fix for this be as simple as adding
to the init function and
to descriptor swith statement of AVCaptureColorSpace? Or what are the side effects of commenting the code as in @thyxus patch?
Found a co worker with the new iphone 15 pro and can confirm that patching 2.15.4 with this code is working! 🎉
my bad lol, the error message is wrong here.
Will fix this in V3 to make the enum casting safer!
I can confirm that it works. But the build only works with xcode 15. Unfortunately our CI/CD process is using xcode 14 so I end up applying the patch
It seems that you are applying at the wrong file. Correct file is
node_modules/react-native-vision-camera/ios/Parsers/AVCaptureColorSpace+descriptor.swift
Seems like you are applying atnode_modules/react-native-vision-camera/ios/Parsers/AVCaptureDevice+descriptor.swift
I applied this commit as a patch and it worked.
RNVC 2.15.6. But soon I’ll update to RNVC v3
Mukthayar1(https://github.com/mrousavy/react-native-vision-camera/issues/1840#issuecomment-1752964704)
@mrousavy, I am experiencing the same problem!
Will there be a release of V2 that fixes this?
This patch seems to be working for me on iPhone 15 Pro 👍🏻 We do not use anything regarding colorSpaces in our app.
Would be great if someone with access to on iPhone 15 Pro or 15 Pro Max were able to add logging to see what the actual unknown state is, since there is no new reference in the iOS documentation for what the new state value is.