From a966b7b6a63f6f9a7d3496fcb09aa9924ccc138c Mon Sep 17 00:00:00 2001 From: Scott Goodson Date: Wed, 16 Mar 2016 20:55:08 -0700 Subject: [PATCH] [ASImageNode] -setDefaultImage: should release lock before calling -setImage: This allows -setImage: to fully unlock before it calls -invalidateCalculatedSize. --- AsyncDisplayKit/ASNetworkImageNode.mm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/AsyncDisplayKit/ASNetworkImageNode.mm b/AsyncDisplayKit/ASNetworkImageNode.mm index 5b5f97e793..1a1ce26887 100755 --- a/AsyncDisplayKit/ASNetworkImageNode.mm +++ b/AsyncDisplayKit/ASNetworkImageNode.mm @@ -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(); } }