Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Vision Camera crashes when built with Xcode 14 #1244

Closed
jpudysz opened this issue Sep 15, 2022 · 33 comments 路 Fixed by #1308
Closed

馃悰 Vision Camera crashes when built with Xcode 14 #1244

jpudysz opened this issue Sep 15, 2022 · 33 comments 路 Fixed by #1308
Labels
馃悰 bug Something isn't working

Comments

@jpudysz
Copy link

jpudysz commented Sep 15, 2022

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.
@jpudysz jpudysz added the 馃悰 bug Something isn't working label Sep 15, 2022
@baylesa-dev
Copy link

Hello @jpudysz, could you add your react-native/react-native-vision-camera versions please ? :)

@jpudysz
Copy link
Author

jpudysz commented Sep 15, 2022

Sure!

"react-native": "0.69.5",
"react-native-vision-camera": "2.14.1",
"vision-camera-code-scanner": "0.2.0"

@icc-guerrero
Copy link
Contributor

Similar issue here.

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

@baylesa-dev
Copy link

baylesa-dev commented Sep 15, 2022

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

@jpudysz
Copy link
Author

jpudysz commented Sep 15, 2022

Nice catch @baylesa-dev!
The problem is that we can't even call this plugin. It breaks before callback:
https://github.com/rodgomesc/vision-camera-code-scanner/blob/0571128d46a4a7564aca97d9271c8f7c0b67a5d7/ios/VisionCameraCodeScanner.swift#L11

@baylesa-dev
Copy link

Yep!

console.log(typeof __labelImage) // => function
console.log(typeof __scanCodes) // => undefined

@jpudysz
Copy link
Author

jpudysz commented Sep 15, 2022

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.

@sacmii
Copy link

sacmii commented Sep 15, 2022

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

Same issue

@baylesa-dev
Copy link

Mentioned in facebook/react-native#34673 (comment)

@ArturoTorresMartinez
Copy link

ArturoTorresMartinez commented Sep 15, 2022

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

Or is there a temp workaround?

@jpudysz
Copy link
Author

jpudysz commented Sep 16, 2022

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.

@ArturoTorresMartinez
Copy link

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! 馃憤

@bglgwyng
Copy link
Sponsor Contributor

bglgwyng commented Sep 18, 2022

I have this issue after upgrading RN to 0.70.1
My XCode version is 13.4.1.

I made a repo to reproduce the issue.
https://github.com/bglgwyng/FrameProcessorExample2

In my case, scanCodes from vision-camera-code-scanner works fine.
However, my custom empty frame processor xyz that is scaffolled with vision-camera-plugin-builder crashes the app with the same error message here.

@Neklan
Copy link

Neklan commented Sep 22, 2022

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

@intmain
Copy link

intmain commented Sep 28, 2022

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.

@EasonLex
Copy link

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.

Thanks @intmain , it fixed the issue for me temporarily too. It seems that using attribute((constructor)) no longer works with load() and not sure why swift bridge to objc works (using +(void)load )

(I'm not familiar with swift, so if I was wrong with something, please correct me.)

@Neklan
Copy link

Neklan commented Sep 30, 2022

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

@bglgwyng
Copy link
Sponsor Contributor

bglgwyng commented Oct 1, 2022

@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.

@zzz08900
Copy link
Sponsor Contributor

zzz08900 commented Oct 1, 2022

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.

Thanks man, issue fixed too.

@zzz08900
Copy link
Sponsor Contributor

zzz08900 commented Oct 1, 2022

@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.

@Neklan
Copy link

Neklan commented Oct 3, 2022

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

@alexco2
Copy link

alexco2 commented Oct 3, 2022

@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

@le-blip
Copy link

le-blip commented Oct 10, 2022

Same issue in android, please help me . Have switched back to react native camera which is deprecated.

@ikuruzum
Copy link

@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

@zzz08900
Copy link
Sponsor Contributor

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

@zzz08900
Copy link
Sponsor Contributor

Same issue in android, please help me . Have switched back to react native camera which is deprecated.

This issue has nothing to do with android, you're facing a different problem

@qtipee
Copy link

qtipee commented Oct 18, 2022

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.

@LazyAfternoons
Copy link
Contributor

LazyAfternoons commented Oct 19, 2022

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

@mrousavy
Copy link
Owner

Huh, that's interesting. I'll take a look to find out if that's safe to do

@mrousavy
Copy link
Owner

Could you create a PR with the change?

@LazyAfternoons
Copy link
Contributor

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.

@euthribeiro
Copy link

@intmain thank you so much!

@LazyAfternoons
Copy link
Contributor

Could you create a PR with the change?

Hey @mrousavy I created the PR with the change proposed by @intmain #1308.
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
馃悰 bug Something isn't working
Projects
None yet