Skip to content

Commit

Permalink
Fix downloadImageWithURL:options:progress:completed returning nil (fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Poitrey authored and devedup committed Sep 10, 2014
1 parent 7b0b750 commit 4177643
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions SDWebImage/SDWebImageDownloader.m
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ - (NSInteger)maxConcurrentDownloads

- (id<SDWebImageOperation>)downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(void (^)(NSUInteger, long long))progressBlock completed:(void (^)(UIImage *, NSData *, NSError *, BOOL))completedBlock
{
__block SDWebImageDownloaderOperation *operation;
__block SDWebImageDownloaderOperation *blockOperation;
__weak SDWebImageDownloader *wself = self;

[self addProgressCallback:progressBlock andCompletedBlock:completedBlock forURL:url createCallback:^
Expand All @@ -121,7 +121,7 @@ - (NSInteger)maxConcurrentDownloads
request.HTTPShouldHandleCookies = NO;
request.HTTPShouldUsePipelining = YES;
request.allHTTPHeaderFields = wself.HTTPHeaders;
operation = [SDWebImageDownloaderOperation.alloc initWithRequest:request options:options progress:^(NSUInteger receivedSize, long long expectedSize)
blockOperation = [SDWebImageDownloaderOperation.alloc initWithRequest:request options:options progress:^(NSUInteger receivedSize, long long expectedSize)
{
if (!wself) return;
SDWebImageDownloader *sself = wself;
Expand Down Expand Up @@ -153,16 +153,17 @@ - (NSInteger)maxConcurrentDownloads
SDWebImageDownloader *sself = wself;
[sself removeCallbacksForURL:url];
}];
[wself.downloadQueue addOperation:operation];
[wself.downloadQueue addOperation:blockOperation];
if (wself.executionOrder == SDWebImageDownloaderLIFOExecutionOrder)
{
// Emulate LIFO execution order by systematically adding new operations as last operation's dependency
[wself.lastAddedOperation addDependency:operation];
wself.lastAddedOperation = operation;
[wself.lastAddedOperation addDependency:blockOperation];
wself.lastAddedOperation = blockOperation;
}
operation = nil; // break retain cycle
}];

id operation = blockOperation;
blockOperation = nil; // break retain cycle
return operation;
}

Expand Down

0 comments on commit 4177643

Please sign in to comment.