react-native-image-sequence icon indicating copy to clipboard operation
react-native-image-sequence copied to clipboard

image is nil in onImagesLoaded

Open trickeyd opened this issue 3 years ago • 0 comments

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

We have an image sequence in our project that pops every now and then. We have never had an issue with it in development, but on production we have an error that crashes the app for about 4% of our users. The error is below:

Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x11b928 __exceptionPreprocess
1  libobjc.A.dylib                0x26480 objc_exception_throw
2  CoreFoundation                 0x187698 -[__NSCFString characterAtIndex:].cold.1
3  CoreFoundation                 0x184f2c -[__NSArrayM insertObject:atIndex:].cold.2
4  CoreFoundation                 0x2b24 -[__NSArrayM insertObject:atIndex:]
5  goss                           0x4cc134 -[RCTImageSequenceView onImagesLoaded] + 62 (RCTImageSequenceView.m:62)
6  goss                           0x4cc020 -[RCTImageSequenceView onImageLoadTaskAtIndex:image:] + 55 (RCTImageSequenceView.m:55)
7  goss                           0x4cbeec __34-[RCTImageSequenceView setImages:]_block_invoke_2 + 35 (RCTImageSequenceView.m:35)
8  libdispatch.dylib              0x602b0 _dispatch_call_block_and_release
9  libdispatch.dylib              0x61298 _dispatch_client_callout
10 libdispatch.dylib              0xfce0 _dispatch_main_queue_callback_4CF$VARIANT$mp
11 CoreFoundation                 0x9a998 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
12 CoreFoundation                 0x94df8 __CFRunLoopRun
13 CoreFoundation                 0x93ed0 CFRunLoopRunSpecific
14 GraphicsServices               0x3570 GSEventRunModal
15 UIKitCore                      0xb302d0 -[UIApplication _run]
16 UIKitCore                      0xb3584c UIApplicationMain
17 goss                           0x8250 main + 14 (main.m:14)
18 libdyld.dylib                  0x1140 start

It seems as though this line can return nil in some circumstances: UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url]]];

This is very odd as we only use local recourses, and we pass them directly in, so no chance that the image itself is not there.

Here is the diff I have added to try and stop the crash, but obviously this will mean that animations may have missing frames, or not be there at all:

diff --git a/node_modules/react-native-image-sequence/ios/RCTImageSequence/RCTImageSequenceView.m b/node_modules/react-native-image-sequence/ios/RCTImageSequence/RCTImageSequenceView.m
index 9038f5f..97ea564 100644
--- a/node_modules/react-native-image-sequence/ios/RCTImageSequence/RCTImageSequenceView.m
+++ b/node_modules/react-native-image-sequence/ios/RCTImageSequence/RCTImageSequenceView.m
@@ -58,7 +58,9 @@
     NSMutableArray *images = [NSMutableArray new];
     for (NSUInteger index = 0; index < _imagesLoaded.allValues.count; index++) {
         UIImage *image = _imagesLoaded[@(index)];
-        [images addObject:image];
+        if(image != nil){
+          [images addObject:image];
+        }
     }
 
     [_imagesLoaded removeAllObjects];

This issue body was partially generated by patch-package.

trickeyd avatar Nov 24 '22 14:11 trickeyd