JimmyDaddy / react-native-image-marker

🙈Adding text or icon watermark to your image using React Native👀👀
https://jimmydaddy.github.io/react-native-image-marker/
MIT License
316 stars 93 forks source link

App crash on SIGABRT only on iOS #84

Closed dilincoln closed 2 years ago

dilincoln commented 2 years ago

Describe the bug App crash when calling ImageMarker.markText. On Android works but on iOS the app close without any log or catch error but on Flipper has this appcrash:

Process:               grupotexas [6103]
Path:                  /Users/USER/Library/Developer/CoreSimulator/Devices/F552590F-750D-4F64-ADFA-6D6887EC3CEF/data/Containers/Bundle/Application/ABCE06CB-3E84-4B8D-9E35-3D61869F9890/grupotexas.app/grupotexas
Identifier:            grupotexas
Version:               1.0.4 (1)
Code Type:             X86-64 (Native)
Parent Process:        launchd_sim [69660]
Responsible:           SimulatorTrampoline [12239]
User ID:               501

Date/Time:             2021-11-15 15:46:56.264 -0300
OS Version:            macOS 11.6.1 (20G219)
Report Version:        12
Anonymous UUID:        C092A330-42F4-24B1-F867-33A1A98625AF

Time Awake Since Boot: 240000 seconds

System Integrity Protection: disabled

Crashed Thread:        24  Dispatch queue: com.apple.root.default-qos

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Application Specific Information:
dyld4 config: DYLD_ROOT_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot 
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
terminating with uncaught exception of type NSException
abort() called
CoreSimulator 776.4 - Device: iPhone 13 Pro Max (F552590F-750D-4F64-ADFA-6D6887EC3CEF) - Runtime: iOS 15.0 (19A339) - DeviceType: iPhone 13 Pro Max

Application Specific Backtrace 1:
0   CoreFoundation                      0x00007fff203fbbb4 __exceptionPreprocess + 242
1   libobjc.A.dylib                     0x00007fff2019ebe7 objc_exception_throw + 48
2   CoreFoundation                      0x00007fff2047bf38 _CFThrowFormattedException + 194
3   CoreFoundation                      0x00007fff2048642e -[__NSPlaceholderDictionary initWithCapacity:].cold.1 + 0
4   CoreFoundation                      0x00007fff20469914 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 251
5   CoreFoundation                      0x00007fff203fa83b +[NSDictionary dictionaryWithObjects:forKeys:count:] + 49
6   grupotexas                          0x000000010df11933 markerImgWithText + 627
7   grupotexas                          0x000000010df14c3d __148-[ImageMarker addText:text:X:Y:color:fontName:fontSize:shadowStyle:textBackgroundStyle:scale:quality:filename:saveFormat:maxSize:resolver:rejecter:]_block_invoke + 493
8   grupotexas                          0x000000010e1bd32d __128-[RCTImageLoader loadImageWithURLRequest:size:scale:clipped:resizeMode:priority:progressBlock:partialLoadBlock:completionBlock:]_block_invoke + 109
9   grupotexas                          0x000000010e1c3b30 __140-[RCTImageLoader loadImageWithURLRequest:size:scale:clipped:resizeMode:priority:attribution:progressBlock:partialLoadBlock:completionBlock:]_block_invoke_3 + 608
10  grupotexas                          0x000000010e1c4f75 __80-[RCTImageLoader decodeImageData:size:scale:clipped:resizeMode:completionBlock:]_block_invoke_2 + 773
11  grupotexas                          0x000000010e1c5c17 __80-[RCTImageLoader decodeImageData:size:scale:clipped:resizeMode:completionBlock:]_block_invoke_3.315 + 775
12  libdispatch.dylib                   0x00007fff20110876 _dispatch_call_block_and_release + 12
13  libdispatch.dylib                   0x00007fff20111a56 _dispatch_client_callout + 8
14  libdispatch.dylib                   0x00007fff201142de _dispatch_queue_override_invoke + 849
15  libdispatch.dylib                   0x00007fff2012207e _dispatch_root_queue_drain + 405
16  libdispatch.dylib                   0x00007fff201229c8 _dispatch_worker_thread2 + 155
17  libsystem_pthread.dylib             0x00007fff6bfeb417 _pthread_wqthread + 244
18  libsystem_pthread.dylib             0x00007fff6bfea42f start_wqthread + 15

{...}

To Reproduce Steps to reproduce the behavior:

  1. Call markText with following options:
    ImageMarker.markText({
    src: 'https://picsum.photos/300/300'
    fontName: 'Nunito_400Regular',
    text: `Example`,
    X: 10,
    Y: 10,
    color: '#ffffff',
    fontSize: 20,
    scale: 1,
    quality: 100,
    }).then(image => {
    console.log(image)
    }).catch(err => {
    console.log(err)
    })

Expected behavior Should log image path on success or log error on failed.

Devlopment environment(please complete the following information):

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

dilincoln commented 2 years ago

I'm using Nunito font from the module @expo-google-fonts/nunito and for some reason on Android the name of regular font is 'Nunito_400Regular' but on iOS is 'Nunito-Regular'.

This error is because the value('Nunito_400Regular' ) of fontName property is passed to NativeModule of the react-native-image-marker but in iOS when the font is imported(By the @expo-google-fonts/nunito i think) as 'Nunito-Regular'.

To discover the right name of font in iOS i was added this code below on file /ios/YOURPROJECTNAME/AppDelegate.m. So when the app starts you can see all fonts available on iOS/Android and they names in log.

...

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
#if defined(FB_SONARKIT_ENABLED) && __has_include(<FlipperKit/FlipperClient.h>)
  InitializeFlipper(application);
#endif
   // THIS CODE v
  for (NSString* family in [UIFont familyNames])
  {
    NSLog(@"%@", family);
    for (NSString* name in [UIFont fontNamesForFamilyName: family])
    {
      NSLog(@" %@", name);
    }
  }
  // THIS CODE ˆ
...

On my app to solve this error i called ImageMarker function as describe below:

import { Platform } from 'react-native'
import ImageMarker from 'react-native-image-marker'

ImageMarker.markText({
    src: 'YOURIMAGE',
    text: 'Lorem ipsum',
    X: 10,
    Y: 10,
    color: "#f2f2f2",
    scale: 1,
    quality: 100,
    fontSize: 20,
    fontName: Platform.OS === 'android' ? 'Nunito_400Regular' : 'Nunito-Regular', // This solved my problem
})