react-native-vision-camera: 🐛 Vision Camera crashes when built with Xcode 14

What were you trying to do?

I was trying to build my app with Xcode 14.

Reproduceable Code

No super fancy code. Simply render the camera with a frame processor. I'm using QR code scanner:


const [frameProcessor, barcodes] = useScanBarcodes([BarcodeFormat.CODE_128])

return (
    <Camera
       device={device}
       isActive={isActive}
       frameProcessorFps={5}
       frameProcessor={frameProcessor}
       style={StyleSheet.absoluteFillObject}
    />
)

What happened instead?

The app crashed with an error from HostFunction.

I can confirm that code works as expected when built with Xcode 13.

Relevant log output

2022-09-15 10:13:26.797643+0200 x[6471:486752] [native] VisionCamera.didSetProps(_:): Updating 13 prop(s)...
2022-09-15 10:13:26.797882+0200 x[6471:487061] [native] VisionCamera.configureCaptureSession(): Configuring Session...
2022-09-15 10:13:26.797894+0200 x[6471:487061] [native] VisionCamera.configureCaptureSession(): Initializing Camera with device com.apple.avfoundation.avcapturedevice.built-in_video:0...
2022-09-15 10:13:26.797906+0200 x[6471:487061] [native] VisionCamera.configureCaptureSession(): Adding Video input...
2022-09-15 10:13:26.798369+0200 x[6471:487075] FrameProcessorBindings: Setting new frame processor...
2022-09-15 10:13:26.798393+0200 x[6471:487075] FrameProcessorBindings: Adapting Shareable value from function (conversion to worklet)...
2022-09-15 10:13:26.798517+0200 x[6471:487075] FrameProcessorBindings: Successfully created worklet!
2022-09-15 10:13:26.798554+0200 x[6471:487097] FrameProcessorBindings: Converting worklet to Objective-C callback...
2022-09-15 10:13:26.799270+0200 x[6471:487097] FrameProcessorBindings: Frame processor set!
2022-09-15 10:13:26.838111+0200 x[6471:487061] [native] VisionCamera.configureCaptureSession(): Adding Video Data output...
2022-09-15 10:13:26.838707+0200 x[6471:487061] [native] VisionCamera.invokeOnInitialized(): Camera initialized!
2022-09-15 10:13:26.838926+0200 x[6471:487061] [native] VisionCamera.configureCaptureSession(): Session successfully configured!
2022-09-15 10:13:26.839396+0200 x[6471:487061] [native] VisionCamera.configureFormat(): Configuring Format...
2022-09-15 10:13:26.839401+0200 x[6471:487061] [native] VisionCamera.configureDevice(): Configuring Device...
2022-09-15 10:13:26.839427+0200 x[6471:487061] [native] VisionCamera.configureDevice(): Device successfully configured!
2022-09-15 10:13:26.839689+0200 x[6471:487061] [native] VisionCamera.didSetProps(_:): Starting Session...
2022-09-15 10:13:27.007614+0200 x[6471:487061] [native] VisionCamera.didSetProps(_:): Started Session!
libc++abi: terminating with uncaught exception of type facebook::jsi::JSError: Exception in HostFunction: Javascript worklet error

Error: Javascript worklet error
    at _f (native)

Error: Exception in HostFunction: Javascript worklet error

Error: Javascript worklet error
    at _f (native)
    at _f (native)
terminating with uncaught exception of type facebook::jsi::JSError: Exception in HostFunction: Javascript worklet error

Error: Javascript worklet error
    at _f (native)

Error: Exception in HostFunction: Javascript worklet error

Error: Javascript worklet error
    at _f (native)
    at _f (native)
(Recorded stack frame) 


I've debugged the code and it crashes in FrameProcessorUtils.mm:

cb.callWithThis(runtime, cb, jsi::Object::createFromHostObject(runtime, frameHostObject));

Null pointer exception



### Device

iPhone 13

### VisionCamera Version

2.14.1

### Additional information

- [ ] I am using Expo
- [X] I have read the [Troubleshooting Guide](https://mrousavy.github.io/react-native-vision-camera/docs/guides/troubleshooting)
- [X] I agree to follow this project's [Code of Conduct](https://github.com/mrousavy/react-native-vision-camera/blob/main/CODE_OF_CONDUCT.md)
- [X] I searched for [similar issues in this repository](https://github.com/mrousavy/react-native-vision-camera/issues) and found none.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 28
  • Comments: 33 (12 by maintainers)

Most upvoted comments

@Neklan You can apply that patch with the following patch script and patch-package,

diff --git a/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h b/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h
index a2ccdcb4..7c9690e0 100644
--- a/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h	
+++ b/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h	
@@ -53,7 +53,7 @@ objc_name : NSObject<FrameProcessorPluginBase>
 @end                                                                                \
 @implementation objc_name (FrameProcessorPlugin)                                    \
                                                                                     \
-__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)()    \
++(void)load                                                                         \
 {                                                                                   \
   [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #name callback:^id(Frame* frame, NSArray<id>* args) {    \
     return [objc_name callback:frame withArgs:args];                               \

Sadly, it didn’t fix my problem with custom frame processor https://github.com/mrousavy/react-native-vision-camera/issues/1244#issuecomment-1250233793. Or those problems are irrelevant to each other.

VISION_EXPORT_SWIFT_FRAME_PROCESSOR is working on my main Project, but not working in pod project like vision-camera-code-scanner when build by Xcode 14.0.

If I chagne this code __attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)() to +(void)load

then it work (temporary). I tested it.

I confirm, that solution posted above with changing __attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)() to +(void)load is working on the newest xCode 14.0.1 with custom frame processor

npx vision-camera-plugin-builder ios => Objective C Language Screenshot 2022-09-16 at 12 20 59 AM

Same issue

@Neklan You can apply that patch with the following patch script and patch-package,

diff --git a/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h b/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h
index a2ccdcb4..7c9690e0 100644
--- a/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h	
+++ b/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h	
@@ -53,7 +53,7 @@ objc_name : NSObject<FrameProcessorPluginBase>
 @end                                                                                \
 @implementation objc_name (FrameProcessorPlugin)                                    \
                                                                                     \
-__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)()    \
++(void)load                                                                         \
 {                                                                                   \
   [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #name callback:^id(Frame* frame, NSArray<id>* args) {    \
     return [objc_name callback:frame withArgs:args];                               \

Sadly, it didn’t fix my problem with custom frame processor #1244 (comment). Or those problems are irrelevant to each other.

this fixed the issue for me as well

So far, nothing I’m aware of. I was trying to patch Podfile with the solutions mentioned in the linked issue, and the app is compiling indeed, but vision camera plugins are not working.

We need to wait for a patch from react-native. To run your app smoothly, you need to downgrade Xcode to version 13.4.

Similar issue here.

[javascript] Frame Processor threw an error: Can’t find variable: __xxxx

So far, nothing I’m aware of. I was trying to patch Podfile with the solutions mentioned in the linked issue, and the app is compiling indeed, but vision camera plugins are not working.

We need to wait for a patch from react-native. To run your app smoothly, you need to downgrade Xcode to version 13.4.

Thanks @jpudysz , I can confirm downgrading to version 13.4 solves the issue for now.

I’ll also keep this thread updated if I hear any updates or workarounds.

Thanks! 👍

I also checked vision-camera-face-detector, and it crashed immediately. The only difference between all these plugins is that vision-camera-image-labeler has been written with Objective-C instead of Swift.

I suspect that VISION_EXPORT_SWIFT_FRAME_PROCESSOR is not registering frame processors correctly or something else breaks this registration in Xcode 14.

@mrousavy can you please look at this? Seems to work fine.

@Neklan You can apply that patch with the following patch script and patch-package,

diff --git a/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h b/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h
index a2ccdcb4..7c9690e0 100644
--- a/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h	
+++ b/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h	
@@ -53,7 +53,7 @@ objc_name : NSObject<FrameProcessorPluginBase>
 @end                                                                                \
 @implementation objc_name (FrameProcessorPlugin)                                    \
                                                                                     \
-__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)()    \
++(void)load                                                                         \
 {                                                                                   \
   [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #name callback:^id(Frame* frame, NSArray<id>* args) {    \
     return [objc_name callback:frame withArgs:args];                               \

Sadly, it didn’t fix my problem with custom frame processor #1244 (comment). Or those problems are irrelevant to each other.

how can i make and use that script

@Neklan You can apply that patch with the following patch script and patch-package,

diff --git a/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h b/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h
index a2ccdcb4..7c9690e0 100644
--- a/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h	
+++ b/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h	
@@ -53,7 +53,7 @@ objc_name : NSObject<FrameProcessorPluginBase>
 @end                                                                                \
 @implementation objc_name (FrameProcessorPlugin)                                    \
                                                                                     \
-__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)()    \
++(void)load                                                                         \
 {                                                                                   \
   [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #name callback:^id(Frame* frame, NSArray<id>* args) {    \
     return [objc_name callback:frame withArgs:args];                               \

Sadly, it didn’t fix my problem with custom frame processor #1244 (comment). Or those problems are irrelevant to each other.

The method posted by @intmain only solves crashes caused by upgrading to Xcode 14 - which means if you’re having problems with Xcode 13.x, then the problems are probably elsewhere.

Hmm, I took a look at your frame processor and it seems you didn’t add any code besides the example in doc. If that is the case then I suggest you open a separate issue and ask for help there.

VISION_EXPORT_SWIFT_FRAME_PROCESSOR is working on my main Project, but not working in pod project like vision-> camera-code-scanner when build by Xcode 14.0.

If I chagne this code attribute((constructor)) static void VISION_CONCAT(initialize_, objc_name)() to +(void)load

then it work (temporary). I tested it.

Can you please provide more information on how to modify the code and where, so we can apply it also? Thank you

So far, nothing I’m aware of. I was trying to patch Podfile with the solutions mentioned in the linked issue, and the app is compiling indeed, but vision camera plugins are not working.

We need to wait for a patch from react-native. To run your app smoothly, you need to downgrade Xcode to version 13.4.

Thanks, I confirm that this solution works, for me is just a temporary workaround, because I need to deploy to the latest iOS, so I had to downgrade to Xcode 13.4 and then add support for iOS 16.0

Hope this will be fixed also for the latest Xcode version

In this thread you can find, how to add support

https://developer.apple.com/forums/thread/673131

image

Same here, any more info we can provide to help patch this?

Or is there a temp workaround?

I’m able to reproduce the issue (repro https://github.com/baylesa-dev/rn_vision_camera_xcode_14)

Edit: Just tried with https://github.com/mrousavy/vision-camera-image-labeler, and it works perfectly: the issue seems to be related to the swift implementation of https://github.com/rodgomesc/vision-camera-code-scanner

Could you create a PR with the change?

@intmain or @bglgwyng would you kindly create a PR with the previously mentioned fix? If not I can do that for you.

Thank you.

I confirm that using the patch above works with Xcode 14.0.1 😃

I had no problem when using Objective-C for the iOS native module, but as soon as you use Swift, you need to apply that patch.

@ikuruzum all you need to do is googling “how to use patch-package”