Authored by DreamPiggy

capture currentURL instead of using index to access to avoid race condition

@@ -57,25 +57,21 @@ @@ -57,25 +57,21 @@
57 - (void)startPrefetchingAtIndex:(NSUInteger)index { 57 - (void)startPrefetchingAtIndex:(NSUInteger)index {
58 if (index >= self.prefetchURLs.count) return; 58 if (index >= self.prefetchURLs.count) return;
59 self.requestedCount++; 59 self.requestedCount++;
60 - [self.manager loadImageWithURL:self.prefetchURLs[index] options:self.options progress:nil completed:^(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { 60 + NSURL *currentURL = self.prefetchURLs[index];
  61 + [self.manager loadImageWithURL:currentURL options:self.options progress:nil completed:^(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
61 if (!finished) return; 62 if (!finished) return;
62 self.finishedCount++; 63 self.finishedCount++;
63 64
64 - if (image) {  
65 - if (self.progressBlock) {  
66 - self.progressBlock(self.finishedCount,(self.prefetchURLs).count);  
67 - } 65 + if (self.progressBlock) {
  66 + self.progressBlock(self.finishedCount,(self.prefetchURLs).count);
68 } 67 }
69 - else {  
70 - if (self.progressBlock) {  
71 - self.progressBlock(self.finishedCount,(self.prefetchURLs).count);  
72 - } 68 + if (!image) {
73 // Add last failed 69 // Add last failed
74 self.skippedCount++; 70 self.skippedCount++;
75 } 71 }
76 if ([self.delegate respondsToSelector:@selector(imagePrefetcher:didPrefetchURL:finishedCount:totalCount:)]) { 72 if ([self.delegate respondsToSelector:@selector(imagePrefetcher:didPrefetchURL:finishedCount:totalCount:)]) {
77 [self.delegate imagePrefetcher:self 73 [self.delegate imagePrefetcher:self
78 - didPrefetchURL:self.prefetchURLs[index] 74 + didPrefetchURL:currentURL
79 finishedCount:self.finishedCount 75 finishedCount:self.finishedCount
80 totalCount:self.prefetchURLs.count 76 totalCount:self.prefetchURLs.count
81 ]; 77 ];