From e4aba2e647bb509308b590361f56b8ab8cda433d Mon Sep 17 00:00:00 2001 From: Declan McKenna Date: Tue, 16 Aug 2022 14:40:09 +0300 Subject: [PATCH 1/3] Restrict current lock usage to iOS 15+ --- SDWebImage/Core/SDImageIOAnimatedCoder.m | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/SDWebImage/Core/SDImageIOAnimatedCoder.m b/SDWebImage/Core/SDImageIOAnimatedCoder.m index c21ba47f4..9e9fffb13 100644 --- a/SDWebImage/Core/SDImageIOAnimatedCoder.m +++ b/SDWebImage/Core/SDImageIOAnimatedCoder.m @@ -196,7 +196,9 @@ + (UIImage *)createFrameAtIndex:(NSUInteger)index source:(CGImageSourceRef)sourc kSDImageIOCoderLock = [[NSLock alloc] init]; }); - [kSDImageIOCoderLock lock]; + if (@available(iOS 15, *)) { + [kSDImageIOCoderLock lock]; + } // Some options need to pass to `CGImageSourceCopyPropertiesAtIndex` before `CGImageSourceCreateImageAtIndex`, or ImageIO will ignore them because they parse once :) // Parse the image properties @@ -237,7 +239,9 @@ + (UIImage *)createFrameAtIndex:(NSUInteger)index source:(CGImageSourceRef)sourc imageRef = CGImageSourceCreateThumbnailAtIndex(source, index, (__bridge CFDictionaryRef)[decodingOptions copy]); } if (!imageRef) { - [kSDImageIOCoderLock unlock]; + if (@available(iOS 15, *)) { + [kSDImageIOCoderLock unlock]; + } return nil; } // Thumbnail image post-process @@ -260,7 +264,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, *)) { + [kSDImageIOCoderLock unlock]; + } return image; } From 9038c7f8300ba07e66bc104949611b134c1088f6 Mon Sep 17 00:00:00 2001 From: Declan McKenna Date: Tue, 16 Aug 2022 14:40:46 +0300 Subject: [PATCH 2/3] Restrict access of lock to iOS15+ --- SDWebImage/Core/SDImageIOAnimatedCoder.m | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/SDWebImage/Core/SDImageIOAnimatedCoder.m b/SDWebImage/Core/SDImageIOAnimatedCoder.m index 9e9fffb13..eb61e44e3 100644 --- a/SDWebImage/Core/SDImageIOAnimatedCoder.m +++ b/SDWebImage/Core/SDImageIOAnimatedCoder.m @@ -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 @@ -191,12 +191,11 @@ + (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]; - }); - if (@available(iOS 15, *)) { + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + kSDImageIOCoderLock = [[NSLock alloc] init]; + }); [kSDImageIOCoderLock lock]; } From b7cccded9a09c8dc5e33d0297063c21446903ede Mon Sep 17 00:00:00 2001 From: Declan McKenna Date: Tue, 16 Aug 2022 15:25:54 +0300 Subject: [PATCH 3/3] Restrict solution to tvOS15 This was done in Dreampiggy's PR so I assume this too is a requirement for merging. --- SDWebImage/Core/SDImageIOAnimatedCoder.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SDWebImage/Core/SDImageIOAnimatedCoder.m b/SDWebImage/Core/SDImageIOAnimatedCoder.m index eb61e44e3..25c18c480 100644 --- a/SDWebImage/Core/SDImageIOAnimatedCoder.m +++ b/SDWebImage/Core/SDImageIOAnimatedCoder.m @@ -191,7 +191,7 @@ + (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 { - if (@available(iOS 15, *)) { + if (@available(iOS 15, tvOS 15, *)) { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ kSDImageIOCoderLock = [[NSLock alloc] init]; @@ -238,7 +238,7 @@ + (UIImage *)createFrameAtIndex:(NSUInteger)index source:(CGImageSourceRef)sourc imageRef = CGImageSourceCreateThumbnailAtIndex(source, index, (__bridge CFDictionaryRef)[decodingOptions copy]); } if (!imageRef) { - if (@available(iOS 15, *)) { + if (@available(iOS 15, tvOS 15, *)) { [kSDImageIOCoderLock unlock]; } return nil; @@ -263,7 +263,7 @@ + (UIImage *)createFrameAtIndex:(NSUInteger)index source:(CGImageSourceRef)sourc UIImage *image = [[UIImage alloc] initWithCGImage:imageRef scale:scale orientation:exifOrientation]; #endif CGImageRelease(imageRef); - if (@available(iOS 15, *)) { + if (@available(iOS 15, tvOS 15, *)) { [kSDImageIOCoderLock unlock]; } return image;