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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[V2] iOS - App Crashes at Launch when built with Xcode 15 #1802

Closed
3 of 6 tasks
marcshilling opened this issue Sep 14, 2023 · 48 comments
Closed
3 of 6 tasks

[V2] iOS - App Crashes at Launch when built with Xcode 15 #1802

marcshilling opened this issue Sep 14, 2023 · 48 comments
Labels
🐛 bug Something isn't working Fund

Comments

@marcshilling
Copy link

marcshilling commented Sep 14, 2023

What's happening?

When built using Xcode 15 release candidate, the app is crashing at launch. Before the crash, the message Swift class extensions and categories on Swift classes are not allowed to have +load methods is printed to the console.

Relevant info - I'm also using vision-camera-code-scanner@0.2.0 for barcode scanning.

It seems to be related to #1308. If I revert that change, the startup crash goes away, but then when trying to use the camera it lags and then crashes (probably the original issue)

My workaround for now is continuing to use Xcode 14 to build.

Reproduceable Code

N/A

Relevant log output

Code Type:           X86-64 (Native)
Role:                Foreground
Parent Process:      launchd_sim [26423]
Coalition:           com.apple.CoreSimulator.SimDevice.249DDD8B-78A4-4847-98B3-29645FFF9567 [76346]
Responsible Process: SimulatorTrampoline [24850]

Date/Time:           2023-08-25 16:33:58.9305 -0400
Launch Time:         2023-08-25 16:33:57.5265 -0400
OS Version:          macOS 13.5.1 (22G90)
Release Type:        User
Report Version:      104

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Termination Reason: OBJC 1 

Triggered by Thread:  0

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib        	       0x114d49a52 __abort_with_payload + 10
1   libsystem_kernel.dylib        	       0x114d6784e abort_with_payload_wrapper_internal + 82
2   libsystem_kernel.dylib        	       0x114d677fc abort_with_reason + 19
3   libobjc.A.dylib               	    0x7ff800057593 _objc_fatalv(unsigned long long, unsigned long long, char const*, __va_list_tag*) + 121
4   libobjc.A.dylib               	    0x7ff80005751a _objc_fatal(char const*, ...) + 114
5   libobjc.A.dylib               	    0x7ff80004166d load_images + 1383
6   dyld_sim                      	       0x11389509b dyld4::RuntimeState::notifyObjCInit(dyld4::Loader const*) + 359
7   dyld_sim                      	       0x11389a73c dyld4::Loader::runInitializersBottomUp(dyld4::RuntimeState&, dyld3::Array<dyld4::Loader const*>&) const + 182
8   dyld_sim                      	       0x11389d49a dyld4::Loader::runInitializersBottomUpPlusUpwardLinks(dyld4::RuntimeState&) const::$_1::operator()() const + 92
9   dyld_sim                      	       0x11389a7dd dyld4::Loader::runInitializersBottomUpPlusUpwardLinks(dyld4::RuntimeState&) const + 93
10  dyld_sim                      	       0x1138b03df dyld4::APIs::runAllInitializersForMain() + 263
11  dyld_sim                      	       0x11388c10a dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*) + 2535
12  dyld_sim                      	       0x11388b356 _dyld_sim_prepare + 854
13  dyld                          	       0x117f55424 dyld4::prepareSim(dyld4::RuntimeState&, char const*) + 1490
14  dyld                          	       0x117f53abc dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*) + 249
15  dyld                          	       0x117f533bd start + 1805

Camera Device

N/A

Device

iPhone 14 Pro

VisionCamera Version

2.15.4

Can you reproduce this issue in the VisionCamera Example app?

  • I can reproduce the issue in the VisionCamera Example app.

Additional information

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@marcshilling marcshilling added the 🐛 bug Something isn't working label Sep 14, 2023
@EldhoseKuriakose
Copy link

Same issue after updating to xcode 15

@ms314006
Copy link

ms314006 commented Sep 19, 2023

Same issue after updating to xcode 15

Same issue here 😭, This message is printed to the xcode15 console before crashed:

Screenshot 2023-09-19 at 11 36 56 PM

@marcshilling Do you have any solution for the issue? I will be grateful for anything you can reply. 🙏

@phatmovista
Copy link

phatmovista commented Sep 19, 2023

So basically the breaking change from Xcode 13 -> 14 is now reverted with Xcode 14 -> 15? 😂

@marcshilling
Copy link
Author

marcshilling commented Sep 19, 2023

@ms314006 Just keep using Xcode 14 for now. I recommend using https://github.com/XcodesOrg/xcodes to manage Xcode versions. But we need to get this resolved eventually, because at some point next year Apple will likely require Xcode 15 for submissions.

@phatmovista Yes, but unfortunately reverting it is not an option because the app crashes when using the camera (the original reason the change was put in: #1308)

@jenskuhrjorgensen
Copy link

@mrousavy this is hitting us too. Does V3 work with Xcode 15 or is this bug also present in V3?

@QSuraj
Copy link

QSuraj commented Sep 20, 2023

Facing the same issue. App crashes on launch.

@bfar97
Copy link

bfar97 commented Sep 20, 2023

Facing the same issue! Any workarounds for this on xcode 15?

@dimisus
Copy link

dimisus commented Sep 20, 2023

Yep, same issue. Xcode 15 (15A240d).

@boticas
Copy link

boticas commented Sep 20, 2023

Same issue here. It works with Xcode 14, but can't build for iOS 17.

@QSuraj
Copy link

QSuraj commented Sep 20, 2023

This should be related to this #1307 (comment)

@dimisus
Copy link

dimisus commented Sep 20, 2023

Downgraded to 14.3.1. It worked.

https://developer.apple.com/download/applications/

@gabrielmaldi
Copy link

I'm on version 2.15.4 and had to replace

+(void)load

with

__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)()

in two lines in the file ./ios/Frame Processor/FrameProcessorPlugin.h:

This avoids the initial crash. Haven't tried the camera which I assume will crash as stated in #1307 (comment).

@DanielAraldi
Copy link

I'm on version 2.15.4 and had to replace

+(void)load

with

__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)()

in two lines in the file ./ios/Frame Processor/FrameProcessorPlugin.h:

This avoids the initial crash. Haven't tried the camera which I assume will crash as stated in #1307 (comment).

Thank you, that's worked for me!

Note: I am using RN 0.68.2 here.

@marcshilling
Copy link
Author

@gabrielmaldi @DanielAraldi be warned (I mentioned this in my original comment), the reversion fixes the startup crash but the original crash (using the camera with a frame processor) will pop back up, making the fix unusable

@gabrielmaldi
Copy link

Yes, this is a temporary fix to be able to at least work on the rest of the app. Thanks a lot.

@erissun
Copy link

erissun commented Sep 21, 2023

I'm on version 2.15.4 and had to replace

+(void)load

with

__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)()

in two lines in the file ./ios/Frame Processor/FrameProcessorPlugin.h:

This avoids the initial crash. Haven't tried the camera which I assume will crash as stated in #1307 (comment).

still got this issue on RN 0.69.3

@QSuraj
Copy link

QSuraj commented Sep 21, 2023

The quick fix for now is to revert this change - https://github.com/mrousavy/react-native-vision-camera/pull/1308/files

Replacing vision-camera-code-scanner with react-native-camera-kit.

That solved the issue for me.

@2sem
Copy link

2sem commented Sep 21, 2023

crash is resolved with this. thx

__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)()

however I can't use camera.

"react-native-vision-camera": "2.16.1",
"react-native": "0.68.7",
__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)() \
{                                                                                   \
  [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #name callback:^id(Frame* frame, NSArray<id>* args) {    \
    return [objc_name callback:frame withArgs:args];                               \
  }];                                                                               \
}

Screenshot 2023-09-21 at 11 21 36 PM

@QSuraj
Copy link

QSuraj commented Sep 22, 2023

This should solve the issue permanently - #1307 (comment)

@frenberg
Copy link

frenberg commented Sep 22, 2023

This should solve the issue permanently - #1307 (comment)

Still get the red screen above "Frame Processors are not enabled...". I'm on 2.15.4 and changing my FrameProcessorPlugin.h like below according to the solution above didn't help. Obviously did a clean build. What am i missing? :)

//
//  FrameProcessorPlugin.h
//  VisionCamera
//
//  Created by Marc Rousavy on 01.05.21.
//  Copyright © 2021 mrousavy. All rights reserved.
//

#ifndef FrameProcessorPlugin_h
#define FrameProcessorPlugin_h

#import <Foundation/Foundation.h>
#import "FrameProcessorPluginRegistry.h"
#import "Frame.h"

@protocol FrameProcessorPluginBase
+ (id) callback:(Frame*)frame withArgs:(NSArray<id>*)args;
@end


#define VISION_CONCAT2(A, B) A##B
#define VISION_CONCAT(A, B) VISION_CONCAT2(A, B)

/**
 * Use this Macro to register the given function as a Frame Processor.
 * * Make sure the given function is a C-style function with the following signature: static inline id callback(Frame* frame, NSArray* args)
 * * Make sure the given function's name is unique across other frame processor plugins
 * * Make sure your frame processor returns a Value that can be converted to JS
 * * Make sure to use this Macro in an @implementation, not @interface
 *
 * The JS function will have the same name as the given Objective-C function, but with a "__" prefix.
 * Make sure to add that function to the babel.config.js under reanimated's "globals" option, and add TypeScript type declarations.
 */
#define VISION_EXPORT_FRAME_PROCESSOR(frame_processor)                              \
                                                                                    \
__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)()    \
{                                                                                   \
  [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #frame_processor callback:^id(Frame* frame, NSArray<id>* args) { \
    return frame_processor(frame, args);                                           \
  }];                                                                               \
}


/**
 * Same as VISION_EXPORT_FRAME_PROCESSOR, but uses __attribute__((constructor)) for
 * registration. Useful for registering swift classes that forbids use of +(void)load.
 */
#define VISION_EXPORT_SWIFT_FRAME_PROCESSOR(name, objc_name) \
objc_name : NSObject<FrameProcessorPluginBase>                                      \
@end                                                                                \
                                                                                    \
@interface objc_name (FrameProcessorPlugin) <FrameProcessorPluginBase>              \
@end                                                                                \
@implementation objc_name (FrameProcessorPlugin)                                    \
                                                                                    \
__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)()    \
{                                                                                   \
  [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #name callback:^id(Frame* frame, NSArray<id>* args) {    \
    return [objc_name callback:frame withArgs:args];                               \
  }];                                                                               \
}

#endif /* FrameProcessorPlugin_h */

edit: and chrome dubug not connected etc. This was working before xcode 15/ios 17.

@QSuraj
Copy link

QSuraj commented Sep 22, 2023


#define VISION_EXPORT_SWIFT_FRAME_PROCESSOR(frame_processor)                              \
                                                                                    \
__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)()    \

Should be


#define VISION_EXPORT_SWIFT_FRAME_PROCESSOR(frame_processor)                              \
                                                                              
+(void)load   \

@frenberg

@2sem
Copy link

2sem commented Sep 22, 2023

"react-native-vision-camera": "2.15.4",
"react-native": "0.68.7",
#define VISION_EXPORT_SWIFT_FRAME_PROCESSOR(name, objc_name) \
...
__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)() \

Screenshot 2023-09-22 at 10 40 22 PM

@QSuraj
Copy link

QSuraj commented Sep 22, 2023

@2sem
You also need to make this change #1307 (comment)

@2sem
Copy link

2sem commented Sep 22, 2023

My 2.15.4 FrameProcessorPlugin

#define VISION_CONCAT2(A, B) A##B
#define VISION_CONCAT(A, B) VISION_CONCAT2(A, B)

/**
 * Use this Macro to register the given function as a Frame Processor.
 * * Make sure the given function is a C-style function with the following signature: static inline id callback(Frame* frame, NSArray* args)
 * * Make sure the given function's name is unique across other frame processor plugins
 * * Make sure your frame processor returns a Value that can be converted to JS
 * * Make sure to use this Macro in an @implementation, not @interface
 *
 * The JS function will have the same name as the given Objective-C function, but with a "__" prefix.
 * Make sure to add that function to the babel.config.js under reanimated's "globals" option, and add TypeScript type declarations.
 */
#define VISION_EXPORT_FRAME_PROCESSOR(frame_processor)                              \
                                                                                    \
+(void)load                                                                         \
{                                                                                   \
  [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #frame_processor callback:^id(Frame* frame, NSArray<id>* args) { \
    return frame_processor(frame, args);                                           \
  }];                                                                               \
}


/**
 * Same as VISION_EXPORT_FRAME_PROCESSOR, but uses __attribute__((constructor)) for
 * registration. Useful for registering swift classes that forbids use of +(void)load.
 */
#define VISION_EXPORT_SWIFT_FRAME_PROCESSOR(name, objc_name) \
objc_name : NSObject<FrameProcessorPluginBase>                                      \
@end                                                                                \
                                                                                    \
@interface objc_name (FrameProcessorPlugin)                                         \
@end                                                                                \
@implementation objc_name (FrameProcessorPlugin)                                    \
                                                                                    \
__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)() \
{                                                                                   \
  [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #name callback:^id(Frame* frame, NSArray<id>* args) {    \
    return [objc_name callback:frame withArgs:args];                               \
  }];                                                                               \
}

@Thormeard
Copy link

Hi, got the same issue. (2.16.1)
Managed to fix crashing on startup with #1307 (comment)
But still got an error when trying to use frame processor: frame-processor/unavailable: Frame Processors are not enabled.

Anything else im missing?

My FrameProcessorPlugin.h

//
//  FrameProcessorPlugin.h
//  VisionCamera
//
//  Created by Marc Rousavy on 01.05.21.
//  Copyright © 2021 mrousavy. All rights reserved.
//

#ifndef FrameProcessorPlugin_h
#define FrameProcessorPlugin_h

#import <Foundation/Foundation.h>
#import "FrameProcessorPluginRegistry.h"
#import "Frame.h"

@protocol FrameProcessorPluginBase
+ (id) callback:(Frame*)frame withArgs:(NSArray<id>*)args;
@end


#define VISION_CONCAT2(A, B) A##B
#define VISION_CONCAT(A, B) VISION_CONCAT2(A, B)

/**
 * Use this Macro to register the given function as a Frame Processor.
 * * Make sure the given function is a C-style function with the following signature: static inline id callback(Frame* frame, NSArray* args)
 * * Make sure the given function's name is unique across other frame processor plugins
 * * Make sure your frame processor returns a Value that can be converted to JS
 * * Make sure to use this Macro in an @implementation, not @interface
 *
 * The JS function will have the same name as the given Objective-C function, but with a "__" prefix.
 * Make sure to add that function to the babel.config.js under reanimated's "globals" option, and add TypeScript type declarations.
 */
#define VISION_EXPORT_FRAME_PROCESSOR(frame_processor)                              \
                                                                                    \
+(void)load                                                                         \
{                                                                                   \
  [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #frame_processor callback:^id(Frame* frame, NSArray<id>* args) { \
    return frame_processor(frame, args);                                           \
  }];                                                                               \
}


/**
 * Same as VISION_EXPORT_FRAME_PROCESSOR, but uses __attribute__((constructor)) for
 * registration. Useful for registering swift classes that forbids use of +(void)load.
 */
#define VISION_EXPORT_SWIFT_FRAME_PROCESSOR(name, objc_name)                        \
objc_name : NSObject<FrameProcessorPluginBase>                                      \
@end                                                                                \
                                                                                    \
@interface objc_name (FrameProcessorPlugin) <FrameProcessorPluginBase>              \
@end                                                                                \
@implementation objc_name (FrameProcessorPlugin)                                    \
                                                                                    \
__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)()    \
{                                                                                   \
  [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #name callback:^id(Frame* frame, NSArray<id>* args) {    \
    return [objc_name callback:frame withArgs:args];                               \
  }];                                                                               \
}

#endif /* FrameProcessorPlugin_h */

@frenberg
Copy link

@Thormeard, it's final change, worked for me. But only to "react-native-vision-camera": "2.15.2", if I update "react-native-vision-camera" to 2.16.1 I got error(Frame processors not enabled) again, I don't know why .

//
//  FrameProcessorPlugin.h
//  VisionCamera
//
//  Created by Marc Rousavy on 01.05.21.
//  Copyright © 2021 mrousavy. All rights reserved.
//

#ifndef FrameProcessorPlugin_h
#define FrameProcessorPlugin_h

#import <Foundation/Foundation.h>
#import "FrameProcessorPluginRegistry.h"
#import "Frame.h"

@protocol FrameProcessorPluginBase
+ (id) callback:(Frame*)frame withArgs:(NSArray<id>*)args;
@end


#define VISION_CONCAT2(A, B) A##B
#define VISION_CONCAT(A, B) VISION_CONCAT2(A, B)

/**
 * Use this Macro to register the given function as a Frame Processor.
 * * Make sure the given function is a C-style function with the following signature: static inline id callback(Frame* frame, NSArray* args)
 * * Make sure the given function's name is unique across other frame processor plugins
 * * Make sure your frame processor returns a Value that can be converted to JS
 * * Make sure to use this Macro in an @implementation, not @interface
 *
 * The JS function will have the same name as the given Objective-C function, but with a "__" prefix.
 * Make sure to add that function to the babel.config.js under reanimated's "globals" option, and add TypeScript type declarations.
 */
#define VISION_EXPORT_FRAME_PROCESSOR(frame_processor)                              \
                                                                                    \
+(void)load                                                                         \
{                                                                                   \
  [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #frame_processor callback:^id(Frame* frame, NSArray<id>* args) { \
    return frame_processor(frame, args);                                           \
  }];                                                                               \
}


/**
 * Same as VISION_EXPORT_FRAME_PROCESSOR, but uses __attribute__((constructor)) for
 * registration. Useful for registering swift classes that forbids use of +(void)load.
 */
#define VISION_EXPORT_SWIFT_FRAME_PROCESSOR(name, objc_name) \
objc_name : NSObject<FrameProcessorPluginBase>                                      \
@end                                                                                \
                                                                                    \
@interface objc_name (FrameProcessorPlugin) <FrameProcessorPluginBase>                                         \
@end                                                                                \
@implementation objc_name (FrameProcessorPlugin)                                    \
                                                                                    \
__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)() \
{                                                                                   \
  [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #name callback:^id(Frame* frame, NSArray<id>* args) {    \
    return [objc_name callback:frame withArgs:args];                               \
  }];                                                                               \
}

#endif /* FrameProcessorPlugin_h */

If you have patch-package you can apply this:

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 9408774..64180c7 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	
@@ -49,11 +49,11 @@
 objc_name : NSObject<FrameProcessorPluginBase>                                      \
 @end                                                                                \
                                                                                     \
-@interface objc_name (FrameProcessorPlugin)                                         \
+@interface objc_name (FrameProcessorPlugin) <FrameProcessorPluginBase>                                         \
 @end                                                                                \
 @implementation objc_name (FrameProcessorPlugin)                                    \
                                                                                     \
-+(void)load                                                                          \
+__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)() \
 {                                                                                   \
   [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #name callback:^id(Frame* frame, NSArray<id>* args) {    \
     return [objc_name callback:frame withArgs:args];                               \

Also If you have firebase with use_frameworks! :linkage => :static in your pods this can help you (this case give same error: Frame processors not enabled ):

pre_install do |installer|
    installer.pod_targets.each do |pod|
      if pod.name.eql?('VisionCamera') || pod.name.eql?('RNReanimated')
        Pod::UI.puts "#{pod.name}: Using overridden static_framework value of 'true'"
        def pod.build_type
          Pod::BuildType.static_library
        end
      end
    end
  end

#1840 (comment)

And to make v2 work on iPhone 15 you need to add the following to your patch, and build using xcode 15/ios skd 17

diff --git a/node_modules/react-native-vision-camera/ios/Parsers/AVCaptureColorSpace+descriptor.swift b/node_modules/react-native-vision-camera/ios/Parsers/AVCaptureColorSpace+descriptor.swift
index 13a403b..9b30f62 100644
--- a/node_modules/react-native-vision-camera/ios/Parsers/AVCaptureColorSpace+descriptor.swift
+++ b/node_modules/react-native-vision-camera/ios/Parsers/AVCaptureColorSpace+descriptor.swift
@@ -24,6 +24,13 @@ extension AVCaptureColorSpace {
     case "srgb":
       self = .sRGB
       return
+    case "appleLog":
+        if #available(iOS 17, *) {
+          self = .appleLog
+        } else {
+          throw EnumParserError.unsupportedOS(supportedOnOS: "17")
+        }
+        return
     default:
       throw EnumParserError.invalidValue
     }
@@ -37,6 +44,8 @@ extension AVCaptureColorSpace {
       return "p3-d65"
     case .sRGB:
       return "srgb"
+    case .appleLog:
+        return "appleLog"
     default:
       fatalError("AVCaptureDevice.Position has unknown state.")
     }

@ms314006
Copy link

@Thormeard, it's final change, worked for me. But only to "react-native-vision-camera": "2.15.2", if I update "react-native-vision-camera" to 2.16.1 I got error(Frame processors not enabled) again, I don't know why .

//
//  FrameProcessorPlugin.h
//  VisionCamera
//
//  Created by Marc Rousavy on 01.05.21.
//  Copyright © 2021 mrousavy. All rights reserved.
//

#ifndef FrameProcessorPlugin_h
#define FrameProcessorPlugin_h

#import <Foundation/Foundation.h>
#import "FrameProcessorPluginRegistry.h"
#import "Frame.h"

@protocol FrameProcessorPluginBase
+ (id) callback:(Frame*)frame withArgs:(NSArray<id>*)args;
@end


#define VISION_CONCAT2(A, B) A##B
#define VISION_CONCAT(A, B) VISION_CONCAT2(A, B)

/**
 * Use this Macro to register the given function as a Frame Processor.
 * * Make sure the given function is a C-style function with the following signature: static inline id callback(Frame* frame, NSArray* args)
 * * Make sure the given function's name is unique across other frame processor plugins
 * * Make sure your frame processor returns a Value that can be converted to JS
 * * Make sure to use this Macro in an @implementation, not @interface
 *
 * The JS function will have the same name as the given Objective-C function, but with a "__" prefix.
 * Make sure to add that function to the babel.config.js under reanimated's "globals" option, and add TypeScript type declarations.
 */
#define VISION_EXPORT_FRAME_PROCESSOR(frame_processor)                              \
                                                                                    \
+(void)load                                                                         \
{                                                                                   \
  [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #frame_processor callback:^id(Frame* frame, NSArray<id>* args) { \
    return frame_processor(frame, args);                                           \
  }];                                                                               \
}


/**
 * Same as VISION_EXPORT_FRAME_PROCESSOR, but uses __attribute__((constructor)) for
 * registration. Useful for registering swift classes that forbids use of +(void)load.
 */
#define VISION_EXPORT_SWIFT_FRAME_PROCESSOR(name, objc_name) \
objc_name : NSObject<FrameProcessorPluginBase>                                      \
@end                                                                                \
                                                                                    \
@interface objc_name (FrameProcessorPlugin) <FrameProcessorPluginBase>                                         \
@end                                                                                \
@implementation objc_name (FrameProcessorPlugin)                                    \
                                                                                    \
__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)() \
{                                                                                   \
  [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #name callback:^id(Frame* frame, NSArray<id>* args) {    \
    return [objc_name callback:frame withArgs:args];                               \
  }];                                                                               \
}

#endif /* FrameProcessorPlugin_h */

If you have patch-package you can apply this:

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 9408774..64180c7 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	
@@ -49,11 +49,11 @@
 objc_name : NSObject<FrameProcessorPluginBase>                                      \
 @end                                                                                \
                                                                                     \
-@interface objc_name (FrameProcessorPlugin)                                         \
+@interface objc_name (FrameProcessorPlugin) <FrameProcessorPluginBase>                                         \
 @end                                                                                \
 @implementation objc_name (FrameProcessorPlugin)                                    \
                                                                                     \
-+(void)load                                                                          \
+__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)() \
 {                                                                                   \
   [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #name callback:^id(Frame* frame, NSArray<id>* args) {    \
     return [objc_name callback:frame withArgs:args];                               \

Also If you have firebase with use_frameworks! :linkage => :static in your pods this can help you (this case give same error: Frame processors not enabled ):

pre_install do |installer|
    installer.pod_targets.each do |pod|
      if pod.name.eql?('VisionCamera') || pod.name.eql?('RNReanimated')
        Pod::UI.puts "#{pod.name}: Using overridden static_framework value of 'true'"
        def pod.build_type
          Pod::BuildType.static_library
        end
      end
    end
  end

#1840 (comment)

This patch seems to be working for me! thanks!

@marcshilling You can try this patch.

@Thormeard
Copy link

@Thormeard, it's final change, worked for me. But only to "react-native-vision-camera": "2.15.2", if I update "react-native-vision-camera" to 2.16.1 I got error(Frame processors not enabled) again, I don't know why .

//
//  FrameProcessorPlugin.h
//  VisionCamera
//
//  Created by Marc Rousavy on 01.05.21.
//  Copyright © 2021 mrousavy. All rights reserved.
//

#ifndef FrameProcessorPlugin_h
#define FrameProcessorPlugin_h

#import <Foundation/Foundation.h>
#import "FrameProcessorPluginRegistry.h"
#import "Frame.h"

@protocol FrameProcessorPluginBase
+ (id) callback:(Frame*)frame withArgs:(NSArray<id>*)args;
@end


#define VISION_CONCAT2(A, B) A##B
#define VISION_CONCAT(A, B) VISION_CONCAT2(A, B)

/**
 * Use this Macro to register the given function as a Frame Processor.
 * * Make sure the given function is a C-style function with the following signature: static inline id callback(Frame* frame, NSArray* args)
 * * Make sure the given function's name is unique across other frame processor plugins
 * * Make sure your frame processor returns a Value that can be converted to JS
 * * Make sure to use this Macro in an @implementation, not @interface
 *
 * The JS function will have the same name as the given Objective-C function, but with a "__" prefix.
 * Make sure to add that function to the babel.config.js under reanimated's "globals" option, and add TypeScript type declarations.
 */
#define VISION_EXPORT_FRAME_PROCESSOR(frame_processor)                              \
                                                                                    \
+(void)load                                                                         \
{                                                                                   \
  [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #frame_processor callback:^id(Frame* frame, NSArray<id>* args) { \
    return frame_processor(frame, args);                                           \
  }];                                                                               \
}


/**
 * Same as VISION_EXPORT_FRAME_PROCESSOR, but uses __attribute__((constructor)) for
 * registration. Useful for registering swift classes that forbids use of +(void)load.
 */
#define VISION_EXPORT_SWIFT_FRAME_PROCESSOR(name, objc_name) \
objc_name : NSObject<FrameProcessorPluginBase>                                      \
@end                                                                                \
                                                                                    \
@interface objc_name (FrameProcessorPlugin) <FrameProcessorPluginBase>                                         \
@end                                                                                \
@implementation objc_name (FrameProcessorPlugin)                                    \
                                                                                    \
__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)() \
{                                                                                   \
  [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #name callback:^id(Frame* frame, NSArray<id>* args) {    \
    return [objc_name callback:frame withArgs:args];                               \
  }];                                                                               \
}

#endif /* FrameProcessorPlugin_h */

If you have patch-package you can apply this:

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 9408774..64180c7 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	
@@ -49,11 +49,11 @@
 objc_name : NSObject<FrameProcessorPluginBase>                                      \
 @end                                                                                \
                                                                                     \
-@interface objc_name (FrameProcessorPlugin)                                         \
+@interface objc_name (FrameProcessorPlugin) <FrameProcessorPluginBase>                                         \
 @end                                                                                \
 @implementation objc_name (FrameProcessorPlugin)                                    \
                                                                                     \
-+(void)load                                                                          \
+__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)() \
 {                                                                                   \
   [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #name callback:^id(Frame* frame, NSArray<id>* args) {    \
     return [objc_name callback:frame withArgs:args];                               \

Also If you have firebase with use_frameworks! :linkage => :static in your pods this can help you (this case give same error: Frame processors not enabled ):

pre_install do |installer|
    installer.pod_targets.each do |pod|
      if pod.name.eql?('VisionCamera') || pod.name.eql?('RNReanimated')
        Pod::UI.puts "#{pod.name}: Using overridden static_framework value of 'true'"
        def pod.build_type
          Pod::BuildType.static_library
        end
      end
    end
  end

#1840 (comment)

Can confirm, fixes issue for me BUT only on 2.15.2 (not on latest 2.16.1). Thanks!

Xcode 15, ios 17, iPhone X

@parthasarathi95
Copy link

I'm on version 2.15.4 and had to replace

+(void)load

with

__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)()

in two lines in the file ./ios/Frame Processor/FrameProcessorPlugin.h:

This avoids the initial crash. Haven't tried the camera which I assume will crash as stated in #1307 (comment).

Thank you ^ 999999999999

@marcshilling
Copy link
Author

marcshilling commented Sep 27, 2023

Confirming the patch posted by @Letitbe93 has me back in business in conjunction with what @frenberg posted (to fix #1840). Building with Xcode 15 and barcode scanning working well on my iPhone 15 Pro 👍

@polar-sh polar-sh bot added the Fund label Sep 27, 2023
@vincicat
Copy link

vincicat commented Sep 28, 2023

I can confirm the FrameProccessor patch (#1802 (comment)) work on XCode 15 with iOS 16 + RN0.70 + react-native-vision-camera@2.15.6 + react-native-reanimated@2.17.0, android need further testing but it should work.

* it seems that v2.16 has some changes on FrameProcessor so we may need to stick to v2.15.6 for a while ... @mrousavy or other contributor can make a patch on 2.15 branch to fix XCode 15 and iPhone 15 issues first.

here is the diff for quick check
v2.15.6...v2.16.0

@mrousavy
Copy link
Owner

Hey - yea please submit a PR instead of creating random patches. Then I can merge and backport it.

@vogdev
Copy link

vogdev commented Oct 2, 2023

if you upgrade the macOS to Sonoma you can't use xcode v14 anymore and this problem happens only on xcode v15 with xcode tools v15 🤷‍♂️

@ryadav1495
Copy link

Any fix for this issue.
I am using

Xcode 15 ,
 "react-native-vision-camera": "2.15.4",
 iOS :17

App is crashing on my simulator after launch.

@dimisus
Copy link

dimisus commented Oct 5, 2023

if you upgrade the macOS to Sonoma you can't use xcode v14 anymore and this problem happens only on xcode v15 with xcode tools v15 🤷‍♂️

I have an M2 on Sonoma running XCode 14.3.1

  1. download 14.x: https://developer.apple.com/download/applications/
  2. open dmg and paste+rename the app to your Applications folder (like XCode_14)
  3. sudo xcode-select -s /Applications/XCode_14.app/ to use the v14 app by default

@oortiz-2020104
Copy link

if you upgrade the macOS to Sonoma you can't use xcode v14 anymore and this problem happens only on xcode v15 with xcode tools v15 🤷‍♂️

I have an M2 on Sonoma running XCode 14.3.1

  1. download 14.x: https://developer.apple.com/download/applications/
  2. open dmg and paste+rename the app to your Applications folder (like XCode_14)
  3. sudo xcode-select -s /Applications/XCode_14.app/ to use the v14 app by default

I just did everything you mentioned but I can't open the new Xcode I installed, but I can't open the version I downloaded, when I run the command sudo xcode-select -s /Applications/XCode_14.app/ and then sudo xcode-select -p It shows that I am using the new version that I installed > /Applications/Xcode_14.app/Contents/Developer

I don't know if this is right or if I have to do something additional.

@shilpa12233
Copy link

My app runs fine on simulator, RN 0.68.2 but crashes in react core pod RCTCxxBridge file - at _reactInstance.reset(new Instance); when I try running on device. iOS - 17, iphone 15, xcode 15

Repository owner deleted a comment from Mukthayar1 Oct 7, 2023
@rafaelmotta
Copy link

gettins this issue also on xcode 15 + iOS 17+ vision camera 3.3.1.

@devtyty
Copy link

devtyty commented Oct 10, 2023

This patch worked for me!

react-native: 0.71.13
react-native-camera-vision: 2.15.4
xcode: 15
macos: 14.0

Create file patch with name -> ./patches/react-native-vision-camera+2.15.4.patch

Past content below to file

npx 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 9408774..2aa04dc 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	
@@ -33,7 +33,7 @@
  */
 #define VISION_EXPORT_FRAME_PROCESSOR(frame_processor)                              \
                                                                                     \
-+(void)load                                                                         \
+__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)()    \
 {                                                                                   \
   [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #frame_processor callback:^id(Frame* frame, NSArray<id>* args) { \
     return frame_processor(frame, args);                                           \
@@ -53,7 +53,7 @@ objc_name : NSObject<FrameProcessorPluginBase>
 @end                                                                                \
 @implementation objc_name (FrameProcessorPlugin)                                    \
                                                                                     \
-+(void)load                                                                          \
+__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)()    \
 {                                                                                   \
   [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #name callback:^id(Frame* frame, NSArray<id>* args) {    \
     return [objc_name callback:frame withArgs:args];                               \

@suwu150
Copy link

suwu150 commented Oct 12, 2023

PD-6078 fix: Swift class extensions and categories on Swift classes are not allowed to have +load methods team-olulo#4

Yes, I also encountered the problem in 3.3.0 but couldn't solve it。

#1987

@Nandha-d3v
Copy link

This patch worked for me!

react-native: 0.71.13 react-native-camera-vision: 2.15.4 xcode: 15 macos: 14.0

Create file patch with name -> ./patches/react-native-vision-camera+2.15.4.patch

Past content below to file

npx 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 9408774..2aa04dc 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	
@@ -33,7 +33,7 @@
  */
 #define VISION_EXPORT_FRAME_PROCESSOR(frame_processor)                              \
                                                                                     \
-+(void)load                                                                         \
+__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)()    \
 {                                                                                   \
   [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #frame_processor callback:^id(Frame* frame, NSArray<id>* args) { \
     return frame_processor(frame, args);                                           \
@@ -53,7 +53,7 @@ objc_name : NSObject<FrameProcessorPluginBase>
 @end                                                                                \
 @implementation objc_name (FrameProcessorPlugin)                                    \
                                                                                     \
-+(void)load                                                                          \
+__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)()    \
 {                                                                                   \
   [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #name callback:^id(Frame* frame, NSArray<id>* args) {    \
     return [objc_name callback:frame withArgs:args];                               \

But this opens new issue for me on Android.
I endup getting error when launching camera-
frame-processor/unavailable: Frame Processors are not enabled. See https://react-native-vision-camera.com/docs/guides/troubleshooting, js engine: hermes

@vitas61
Copy link

vitas61 commented Jan 10, 2024

iphone 15 pro, iphone 15 pro max
xcode 15
v 2.15.6
I fixed the crash problem on startup and the camera also works
patch file:

diff --git a/node_modules/react-native-vision-camera/ios/Parsers/AVCaptureColorSpace+descriptor.swift b/node_modules/react-native-vision-camera/ios/Parsers/AVCaptureColorSpace+descriptor.swift
index 13a403b..6d0ece2 100644
--- a/node_modules/react-native-vision-camera/ios/Parsers/AVCaptureColorSpace+descriptor.swift
+++ b/node_modules/react-native-vision-camera/ios/Parsers/AVCaptureColorSpace+descriptor.swift
@@ -24,6 +24,13 @@ extension AVCaptureColorSpace {
     case "srgb":
       self = .sRGB
       return
+    case "appleLog":
+      if #available(iOS 17, *) {
+         self = .appleLog
+      } else {
+        throw EnumParserError.unsupportedOS(supportedOnOS: "17")
+      }
+      return
     default:
       throw EnumParserError.invalidValue
     }
@@ -37,8 +44,10 @@ extension AVCaptureColorSpace {
       return "p3-d65"
     case .sRGB:
       return "srgb"
+    case .appleLog:
+      return "appleLog"
     default:
-      fatalError("AVCaptureDevice.Position has unknown state.")
+      return "unknown"
     }
   }
 }

@hrvdm
Copy link

hrvdm commented Jan 11, 2024

This isn't a solution but if you want a workaround that doesn't totally kill quality this works for me on iOS & Android:

useCameraFormat(camera, [{videoResolution: 'max'}])

and

cameraRef?.current?.takePhoto({
      qualityPrioritization: 'balanced', // Maybe doesnt matter, havent tested
});

@mrousavy
Copy link
Owner

useCameraFormat is from V3, I don't think V2 has this?

@hrvdm
Copy link

hrvdm commented Jan 11, 2024

Yeah I'm silly, I got here through another issue- I probably should have properly read this properly before commenting- My issue was crash when taking photos with iso: max

@SHINGPH
Copy link

SHINGPH commented Jan 22, 2024

currently i'm using
RN:0.70
VISION-CAMERA:2.14.1
REANIMATED:2.10.0
XCODE 14
ISSUE: VISION-CAMERA-FACE-RECOGNITION CRASH

@mikoprus
Copy link

Experienced this issue for V3 on XCode 15.0, updating to 15.2 solved the problem

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

No branches or pull requests