Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
[ASImageNode] -setDefaultImage: should release lock before calling -s…
Browse files Browse the repository at this point in the history
…etImage:

This allows -setImage: to fully unlock before it calls -invalidateCalculatedSize.
  • Loading branch information
appleguy committed Mar 17, 2016
1 parent 5f58b9d commit a966b7b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions AsyncDisplayKit/ASNetworkImageNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,22 @@ - (NSURL *)URL

- (void)setDefaultImage:(UIImage *)defaultImage
{
ASDN::MutexLocker l(_lock);
_lock.lock();

if (ASObjectIsEqual(defaultImage, _defaultImage)) {
_lock.unlock();
return;
}
_defaultImage = defaultImage;

if (!_imageLoaded) {
self.image = _defaultImage;
_lock.unlock();
// Locking: it is important to release _lock before entering setImage:, as it needs to release the lock before -invalidateCalculatedLayout.
// If we continue to hold the lock here, it will still be locked until the next unlock() call, causing a possible deadlock with
// -[ASNetworkImageNode displayWillStart] (which is called on a different thread / main, at an unpredictable time due to ASMainRunloopQueue).
self.image = defaultImage;
} else {
_lock.unlock();
}
}

Expand Down

0 comments on commit a966b7b

Please sign in to comment.