@@ -31,6 +31,10 @@ - (RCTImageLoaderCancellationBlock)decodeImageData:(NSData *)imageData
31
31
completionHandler : (RCTImageLoaderCompletionBlock)completionHandler
32
32
{
33
33
CGImageSourceRef imageSource = CGImageSourceCreateWithData ((CFDataRef )imageData, NULL );
34
+ if (!imageSource) {
35
+ completionHandler (nil , nil );
36
+ return ^{};
37
+ }
34
38
NSDictionary <NSString *, id > *properties = (__bridge_transfer NSDictionary *)CGImageSourceCopyProperties (imageSource, NULL );
35
39
CGFloat loopCount = 0 ;
36
40
if ([[properties[(id )kCGImagePropertyGIFDictionary ] allKeys ] containsObject: (id )kCGImagePropertyGIFLoopCount ]) {
@@ -54,6 +58,9 @@ - (RCTImageLoaderCancellationBlock)decodeImageData:(NSData *)imageData
54
58
for (size_t i = 0 ; i < imageCount; i++) {
55
59
56
60
CGImageRef imageRef = CGImageSourceCreateImageAtIndex (imageSource, i, NULL );
61
+ if (!imageRef) {
62
+ continue ;
63
+ }
57
64
if (!image) {
58
65
image = [UIImage imageWithCGImage: imageRef scale: scale orientation: UIImageOrientationUp];
59
66
}
@@ -64,10 +71,10 @@ - (RCTImageLoaderCancellationBlock)decodeImageData:(NSData *)imageData
64
71
const NSTimeInterval kDelayTimeIntervalDefault = 0.1 ;
65
72
NSNumber *delayTime = frameGIFProperties[(id )kCGImagePropertyGIFUnclampedDelayTime ] ?: frameGIFProperties[(id )kCGImagePropertyGIFDelayTime ];
66
73
if (delayTime == nil ) {
67
- if (i == 0 ) {
74
+ if (delays. count == 0 ) {
68
75
delayTime = @(kDelayTimeIntervalDefault );
69
76
} else {
70
- delayTime = delays[i - 1 ] ;
77
+ delayTime = delays. lastObject ;
71
78
}
72
79
}
73
80
@@ -77,8 +84,8 @@ - (RCTImageLoaderCancellationBlock)decodeImageData:(NSData *)imageData
77
84
}
78
85
79
86
duration += delayTime.doubleValue ;
80
- delays[i] = delayTime;
81
- images[i] = (__bridge_transfer id )imageRef;
87
+ [delays addObject: delayTime] ;
88
+ [images addObject: (__bridge_transfer id )imageRef] ;
82
89
}
83
90
CFRelease (imageSource);
84
91
0 commit comments