jakemarsh / JMImageCache

NSCache based remote-image caching and downloading mechanism for iOS.
http://deallocatedobjects.com/2011/02/19/introducing-jmimagecache/
MIT License
293 stars 60 forks source link

setImageWithURL:key:placeholder:completionBlock: calls itself - EXC_BAD_ACCESS #33

Open afarber opened 10 years ago

afarber commented 10 years ago

There seems a bug in JMImageCache where setImageWithURL:key:placeholder:completionBlock: calls itself, exhausting the stack and resulting in app crash "Thread 1: EXC_BAD_ACCESS"

Please see the http://stackoverflow.com/questions/21063896/jmimagecache-in-a-simple-test-app-crashes-with-exc-bad-access/21064304 for a short app to reproduce it:

#import "ViewController.h"
#import "JMImageCache.h"

static NSString* const kAvatar = @"http://gravatar.com/avatar/55b3816622d935e50098bb44c17663bc.png";

@interface ViewController ()
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    [_imageView setImageWithURL:[NSURL URLWithString:kAvatar]
            placeholder:[UIImage imageNamed:@"male.png"]];
}

@end

xcode

mehulparmar4ever commented 10 years ago

it also happens to me also...

aranjan commented 10 years ago

It happens for me as well, so I've found a workaround: NSURL videoImageURL = [NSURL URLWithString:imageURLString]; if ([[JMImageCache sharedCache] cachedImageForURL:videoImageURL]) { //Put the correct image in the first instance itself cell.thumbnailImage.image = [[JMImageCache sharedCache] cachedImageForURL:videoImageURL]; } else { //Put the placeholder image and then invoke download of image cell.thumbnailImage.image = [UIImage imageNamed:@"nectar_points_background_NEW"]; [[JMImageCache sharedCache] imageForURL:videoImageURL completionBlock:^(UIImage downloadedImage) { cell.thumbnailImage.image = downloadedImage; }]; }