From 7704c1e5b5594ba353b4b53632cfcf53921105dd Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Thu, 4 Jan 2018 20:09:18 +0800 Subject: [PATCH 1/5] Remove the extra memory warning notification for AutoPurgeCache --- SDWebImage/SDImageCache.m | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/SDWebImage/SDImageCache.m b/SDWebImage/SDImageCache.m index e7c84957..a8021e66 100644 --- a/SDWebImage/SDImageCache.m +++ b/SDWebImage/SDImageCache.m @@ -11,31 +11,6 @@ #import "NSImage+WebCache.h" #import "SDWebImageCodersManager.h" -// See https://github.com/rs/SDWebImage/pull/1141 for discussion -@interface AutoPurgeCache : NSCache -@end - -@implementation AutoPurgeCache - -- (nonnull instancetype)init { - self = [super init]; - if (self) { -#if SD_UIKIT - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(removeAllObjects) name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; -#endif - } - return self; -} - -- (void)dealloc { -#if SD_UIKIT - [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; -#endif -} - -@end - - FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { #if SD_MAC return image.size.height * image.size.width; @@ -90,7 +65,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { _config = [[SDImageCacheConfig alloc] init]; // Init the memory cache - _memCache = [[AutoPurgeCache alloc] init]; + _memCache = [[NSCache alloc] init]; _memCache.name = fullNamespace; // Init the disk cache From ff8d23dacf86cc20da201430d38424fdfffe8793 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Thu, 4 Jan 2018 20:11:20 +0800 Subject: [PATCH 2/5] Avoid user accidentally invalidates the session used in shared downloader --- SDWebImage/SDWebImageDownloader.h | 1 + SDWebImage/SDWebImageDownloader.m | 3 +++ 2 files changed, 4 insertions(+) diff --git a/SDWebImage/SDWebImageDownloader.h b/SDWebImage/SDWebImageDownloader.h index ac7e5219..77a0ee8d 100644 --- a/SDWebImage/SDWebImageDownloader.h +++ b/SDWebImage/SDWebImageDownloader.h @@ -250,6 +250,7 @@ typedef SDHTTPHeadersDictionary * _Nullable (^SDWebImageDownloaderHeadersFilterB * Invalidates the managed session, optionally canceling pending operations. * @note If you use custom downloader instead of the shared downloader, you need call this method when you do not use it to avoid memory leak * @param cancelPendingOperations Whether or not to cancel pending operations. + * @note Calling this method on the shared downloader has no effect. */ - (void)invalidateSessionAndCancel:(BOOL)cancelPendingOperations; diff --git a/SDWebImage/SDWebImageDownloader.m b/SDWebImage/SDWebImageDownloader.m index 472559ca..3adc937c 100644 --- a/SDWebImage/SDWebImageDownloader.m +++ b/SDWebImage/SDWebImageDownloader.m @@ -108,6 +108,9 @@ } - (void)invalidateSessionAndCancel:(BOOL)cancelPendingOperations { + if (self == [SDWebImageDownloader sharedDownloader]) { + return; + } if (cancelPendingOperations) { [self.session invalidateAndCancel]; } else { From 31a87af0ab915e204420071f959a4b167d85d1eb Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Sun, 7 Jan 2018 19:55:05 +0800 Subject: [PATCH 3/5] Fix that 0 pixels error should be used when width OR height is zero but not AND --- SDWebImage/SDWebImageDownloaderOperation.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SDWebImage/SDWebImageDownloaderOperation.m b/SDWebImage/SDWebImageDownloaderOperation.m index 8fdab376..f8057041 100644 --- a/SDWebImage/SDWebImageDownloaderOperation.m +++ b/SDWebImage/SDWebImageDownloaderOperation.m @@ -419,7 +419,8 @@ didReceiveResponse:(NSURLResponse *)response image = [[SDWebImageCodersManager sharedInstance] decompressedImageWithImage:image data:&imageData options:@{SDWebImageCoderScaleDownLargeImagesKey: @(shouldScaleDown)}]; } } - if (CGSizeEqualToSize(image.size, CGSizeZero)) { + CGSize imageSize = image.size; + if (imageSize.width == 0 || imageSize.height == 0) { [self callCompletionBlocksWithError:[NSError errorWithDomain:SDWebImageErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : @"Downloaded image has 0 pixels"}]]; } else { [self callCompletionBlocksWithImage:image imageData:imageData error:nil finished:YES]; From a6c0570987f8d650fb7b8aa5d3fe904305e72dab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=BF=E7=A8=8B?= <05050314@163.com> Date: Tue, 9 Jan 2018 21:59:30 +0800 Subject: [PATCH 4/5] Bugfix for loopCount (#2155) If a GIF image has no Netscape 2.0 loop extension, it is meant to play once and then stop --- SDWebImage/SDWebImageGIFCoder.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SDWebImage/SDWebImageGIFCoder.m b/SDWebImage/SDWebImageGIFCoder.m index 69172104..e05d1c0b 100644 --- a/SDWebImage/SDWebImageGIFCoder.m +++ b/SDWebImage/SDWebImageGIFCoder.m @@ -72,7 +72,7 @@ [frames addObject:frame]; } - NSUInteger loopCount = 0; + NSUInteger loopCount = 1; NSDictionary *imageProperties = (__bridge_transfer NSDictionary *)CGImageSourceCopyProperties(source, nil); NSDictionary *gifProperties = [imageProperties valueForKey:(__bridge_transfer NSString *)kCGImagePropertyGIFDictionary]; if (gifProperties) { From 4f4a33030f0c7b44ff35c95950962729810831d2 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Fri, 12 Jan 2018 11:53:50 +0800 Subject: [PATCH 5/5] Update the spec file to define the dependency version for libwebp --- SDWebImage.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SDWebImage.podspec b/SDWebImage.podspec index 3433cd6d..010f9ebe 100644 --- a/SDWebImage.podspec +++ b/SDWebImage.podspec @@ -62,6 +62,6 @@ Pod::Spec.new do |s| 'USER_HEADER_SEARCH_PATHS' => '$(inherited) $(SRCROOT)/libwebp/src' } webp.dependency 'SDWebImage/Core' - webp.dependency 'libwebp' + webp.dependency 'libwebp', '~> 0.5' end end