mrousavy / react-native-vision-camera

πŸ“Έ A powerful, high-performance React Native Camera library.
https://react-native-vision-camera.com
MIT License
6.72k stars 1k forks source link

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

Closed marcshilling closed 8 months ago

marcshilling commented 8 months ago

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 https://github.com/mrousavy/react-native-vision-camera/pull/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?

Additional information

Upvote & Fund

Fund with Polar

EldhoseKuriakose commented 8 months ago

Same issue after updating to xcode 15

ms314006 commented 8 months ago

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 commented 8 months ago

So basically the breaking change from Xcode 13 -> 14 is now reverted with Xcode 14 -> 15? πŸ˜‚

marcshilling commented 8 months ago

@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: https://github.com/mrousavy/react-native-vision-camera/pull/1308)

jenskuhrjorgensen commented 8 months ago

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

QSuraj commented 8 months ago

Facing the same issue. App crashes on launch.

bfar97 commented 8 months ago

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

dimisus commented 8 months ago

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

boticas commented 8 months ago

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

QSuraj commented 8 months ago

This should be related to this https://github.com/mrousavy/react-native-vision-camera/issues/1307#issuecomment-1727199001

dimisus commented 8 months ago

Downgraded to 14.3.1. It worked.

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

gabrielmaldi commented 8 months ago

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:

https://github.com/mrousavy/react-native-vision-camera/blob/9963f4dedc6fbef933fb99e0adca1343f4f5f972/ios/Frame%20Processor/FrameProcessorPlugin.h#L36

https://github.com/mrousavy/react-native-vision-camera/blob/9963f4dedc6fbef933fb99e0adca1343f4f5f972/ios/Frame%20Processor/FrameProcessorPlugin.h#L56

This avoids the initial crash. Haven't tried the camera which I assume will crash as stated in https://github.com/mrousavy/react-native-vision-camera/issues/1307#issuecomment-1727739161.

DanielAraldi commented 8 months ago

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:

https://github.com/mrousavy/react-native-vision-camera/blob/9963f4dedc6fbef933fb99e0adca1343f4f5f972/ios/Frame%20Processor/FrameProcessorPlugin.h#L36

https://github.com/mrousavy/react-native-vision-camera/blob/9963f4dedc6fbef933fb99e0adca1343f4f5f972/ios/Frame%20Processor/FrameProcessorPlugin.h#L56

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 commented 8 months ago

@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 commented 8 months ago

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

erissun commented 8 months ago

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:

https://github.com/mrousavy/react-native-vision-camera/blob/9963f4dedc6fbef933fb99e0adca1343f4f5f972/ios/Frame%20Processor/FrameProcessorPlugin.h#L36

https://github.com/mrousavy/react-native-vision-camera/blob/9963f4dedc6fbef933fb99e0adca1343f4f5f972/ios/Frame%20Processor/FrameProcessorPlugin.h#L56

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 commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

This should solve the issue permanently - https://github.com/mrousavy/react-native-vision-camera/issues/1307#issuecomment-1731248952

frenberg commented 8 months ago

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 commented 8 months ago

#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 commented 8 months ago
"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 commented 8 months ago

@2sem You also need to make this change https://github.com/mrousavy/react-native-vision-camera/issues/1307#issuecomment-1731248952

2sem commented 8 months ago

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 commented 8 months ago

Hi, got the same issue. (2.16.1) Managed to fix crashing on startup with https://github.com/mrousavy/react-native-vision-camera/issues/1307#issuecomment-1731248952 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 */
Letitbe93 commented 8 months ago

@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

https://github.com/mrousavy/react-native-vision-camera/issues/1840#issuecomment-1734259756

frenberg commented 8 months ago

@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 commented 8 months ago

@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 commented 8 months ago

@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 commented 8 months ago

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:

https://github.com/mrousavy/react-native-vision-camera/blob/9963f4dedc6fbef933fb99e0adca1343f4f5f972/ios/Frame%20Processor/FrameProcessorPlugin.h#L36

https://github.com/mrousavy/react-native-vision-camera/blob/9963f4dedc6fbef933fb99e0adca1343f4f5f972/ios/Frame%20Processor/FrameProcessorPlugin.h#L56

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

Thank you ^ 999999999999

marcshilling commented 8 months ago

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 πŸ‘

vincicat commented 8 months ago

I can confirm the FrameProccessor patch (https://github.com/mrousavy/react-native-vision-camera/issues/1802#issuecomment-1735681593) 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 https://github.com/mrousavy/react-native-vision-camera/compare/v2.15.6...v2.16.0

mrousavy commented 8 months ago

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

vogdev commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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 commented 7 months ago

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 commented 7 months ago

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

rafaelmotta commented 7 months ago

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

devtyty commented 7 months ago

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 commented 7 months ago

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

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

https://github.com/mrousavy/react-native-vision-camera/issues/1987

Nandha-d3v commented 7 months ago

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 commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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

hrvdm commented 4 months ago

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 commented 4 months ago

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 commented 3 months ago

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