From 326890b476cd3d2a4b3388b794d991db5acf9c9e Mon Sep 17 00:00:00 2001 From: Olivier Poitrey Date: Tue, 6 Nov 2012 10:14:21 +0100 Subject: [PATCH] Fix disk image cache read not setting memory cache + ensure decodedImageWithImage never fail --- SDWebImage/SDImageCache.m | 10 ++-------- SDWebImage/SDWebImageDecoder.m | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/SDWebImage/SDImageCache.m b/SDWebImage/SDImageCache.m index 3e01be2d..f3a8c3b2 100644 --- a/SDWebImage/SDImageCache.m +++ b/SDWebImage/SDImageCache.m @@ -191,16 +191,10 @@ static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week dispatch_data_apply(dispatchedData, (dispatch_data_applier_t)^(dispatch_data_t region, size_t offset, const void *buffer, size_t size) { - UIImage *diskImage = SDScaledImageForPath(key, [NSData dataWithBytes:buffer length:size]); + UIImage *diskImage = [UIImage decodedImageWithImage:SDScaledImageForPath(key, [NSData dataWithBytes:buffer length:size])]; - if (image) + if (diskImage) { - UIImage *decodedImage = [UIImage decodedImageWithImage:diskImage]; - if (decodedImage) - { - diskImage = decodedImage; - } - [self.memCache setObject:diskImage forKey:key cost:image.size.height * image.size.width * image.scale]; } diff --git a/SDWebImage/SDWebImageDecoder.m b/SDWebImage/SDWebImageDecoder.m index a6dfe6d3..f09810a1 100644 --- a/SDWebImage/SDWebImageDecoder.m +++ b/SDWebImage/SDWebImageDecoder.m @@ -35,7 +35,7 @@ colorSpace, bitmapInfo); CGColorSpaceRelease(colorSpace); - if (!context) return nil; + if (!context) return image; CGRect rect = (CGRect){CGPointZero,{CGImageGetWidth(imageRef), CGImageGetHeight(imageRef)}}; CGContextDrawImage(context, rect, imageRef);