From 0426f0735512e8ae95a32c38088a8437f88f8f9b Mon Sep 17 00:00:00 2001 From: Charlie Savage Date: Tue, 7 May 2013 02:31:59 -0600 Subject: [PATCH] Images can be downloaded in multiple threads. Therefore the call to self.failedURLs containsObject:url must be synchronized to avoid a collection mutation error. --- SDWebImage/SDWebImageManager.m | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/SDWebImage/SDWebImageManager.m b/SDWebImage/SDWebImageManager.m index c5dafcdb..1dcd3768 100644 --- a/SDWebImage/SDWebImageManager.m +++ b/SDWebImage/SDWebImageManager.m @@ -83,7 +83,13 @@ __block SDWebImageCombinedOperation *operation = SDWebImageCombinedOperation.new; __weak SDWebImageCombinedOperation *weakOperation = operation; - if (!url || !completedBlock || (!(options & SDWebImageRetryFailed) && [self.failedURLs containsObject:url])) + BOOL isFailedUrl = NO; + @synchronized(self.failedURLs) + { + isFailedUrl = [self.failedURLs containsObject:url]; + } + + if (!url || !completedBlock || (!(options & SDWebImageRetryFailed) && isFailedUrl)) { if (completedBlock) completedBlock(nil, nil, SDImageCacheTypeNone, NO); return operation;