Michaelvilleneuve / react-native-perspective-image-cropper

Perform custom crop, resizing and perspective correction πŸ“πŸ–Ό
MIT License
306 stars 128 forks source link

Getting native exception on crop - iOS #27

Closed nimrod-zg closed 5 years ago

nimrod-zg commented 5 years ago

We are getting this exception when calling crop() on some iPhone models. We haven't managed to pinpoint the issue exactly, but it seems to be occurring on newer models like the iPhone X, rather than on older ones like the 6. Looking online for this error and finding that the issue happens on newer, presumably faster, iPhones causes us to think it may be some timing issue with accessing the file or something, but we could be in the wrong direction. The issue does not recreate on an iPhone X simulator.

RCTFatalException: Exception '*** 
-[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert
 nil object from objects[0]' was thrown while invoking crop on target 
CustomCropManager with params (
        {
        bottomLeft =         {
            x = "302.3999999999999";
            y = "2419.2";
        };
        bottomRight =         {
            x = "2721.6";
            y = "2419.2";
        };
        height = 4032;
        topLeft =         {
            x = "302.3999999999999";
            y = "403.2";
        };
        topRight =         {
            x = "2721.6";
            y = "403.2";
        };
        width = 3024;
    },
    "file:///PATH/initial_img_1560416408.jpeg",
    65949
)

Any advice on how to solve this, or even debug this, is welcome.

Michaelvilleneuve commented 5 years ago

Hi ! Your params seem ok. Are you sure that the image given at this filepath exists ? You could try to debug it step by step in xcode, that would allow you to understand when a nil object is given.

nimrod-zg commented 5 years ago

A few updates, and some more info that I should have included before -

  1. We managed to recreate this on all testes iOS devices (iPhone 6, 7, X, iPad)
  2. We've tried debugging this using xCode - this issue will not recreate while debugging, even if we build with Release settings, so no luck with that.
  3. Something I failed to mention last time - the input image we pass to the cropper is generated by manually capturing an image with your other library, react-native-document-scanner.

Our current flow -

  1. Manually capture an image using react-native-document-scanner.
  2. Receive the file path of the newly created picture in the onPictureTaken callback, this is similar to/private/var/mobile/Containers/Data/Application/0C941FC0-7A82-4F99-8209-65D7ACD1E0FF/tmp/initial_img_1560416408.jpeg
  3. Prefixing the path with file:// and passing this to the CustomCrop in the initialImage prop.
  4. Call crop(). When not in debug, this causes the error detailed above.

Things to note and open questions -

Michaelvilleneuve commented 5 years ago

Hi @nimrod-zg sorry I don’t have time to help. Have you found a way to fix your problem ?

nimrod-zg commented 5 years ago

@Michaelvilleneuve - closed this issue now as this seems to have been some strange build issue or something. We've just finished releasing a new native version for iOS without making any changes to the code and this seems to have - somewhat frustratingly I must say - completely resolved the issue πŸ€¦β€β™‚ Anyway, we're good now πŸ€·β€β™‚ Thank you!