Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict lock crashfix to iOS15+ #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions SDWebImage/Core/SDImageIOAnimatedCoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// Specify File Size for lossy format encoding, like JPEG
static NSString * kSDCGImageDestinationRequestedFileSize = @"kCGImageDestinationRequestedFileSize";

NSLock *kSDImageIOCoderLock;
NSLock *kSDImageIOCoderLock API_AVAILABLE(ios(15));

@interface SDImageIOCoderFrame : NSObject

Expand Down Expand Up @@ -191,12 +191,13 @@ + (NSTimeInterval)frameDurationAtIndex:(NSUInteger)index source:(CGImageSourceRe

+ (UIImage *)createFrameAtIndex:(NSUInteger)index source:(CGImageSourceRef)source scale:(CGFloat)scale preserveAspectRatio:(BOOL)preserveAspectRatio thumbnailSize:(CGSize)thumbnailSize options:(NSDictionary *)options {

static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
kSDImageIOCoderLock = [[NSLock alloc] init];
});

[kSDImageIOCoderLock lock];
if (@available(iOS 15, tvOS 15, *)) {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
kSDImageIOCoderLock = [[NSLock alloc] init];
});
[kSDImageIOCoderLock lock];
}

// Some options need to pass to `CGImageSourceCopyPropertiesAtIndex` before `CGImageSourceCreateImageAtIndex`, or ImageIO will ignore them because they parse once :)
// Parse the image properties
Expand Down Expand Up @@ -237,7 +238,9 @@ + (UIImage *)createFrameAtIndex:(NSUInteger)index source:(CGImageSourceRef)sourc
imageRef = CGImageSourceCreateThumbnailAtIndex(source, index, (__bridge CFDictionaryRef)[decodingOptions copy]);
}
if (!imageRef) {
[kSDImageIOCoderLock unlock];
if (@available(iOS 15, tvOS 15, *)) {
[kSDImageIOCoderLock unlock];
}
return nil;
}
// Thumbnail image post-process
Expand All @@ -260,7 +263,9 @@ + (UIImage *)createFrameAtIndex:(NSUInteger)index source:(CGImageSourceRef)sourc
UIImage *image = [[UIImage alloc] initWithCGImage:imageRef scale:scale orientation:exifOrientation];
#endif
CGImageRelease(imageRef);
[kSDImageIOCoderLock unlock];
if (@available(iOS 15, tvOS 15, *)) {
[kSDImageIOCoderLock unlock];
}
return image;
}

Expand Down