From dfc73d9cef0f1e2aa1f5385610a1423e159457f5 Mon Sep 17 00:00:00 2001 From: Garrett Moon Date: Thu, 30 Aug 2018 14:08:15 -0700 Subject: [PATCH 1/2] Shouldn't hold the lock while adding subnodes --- Source/ASControlNode.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/ASControlNode.mm b/Source/ASControlNode.mm index c04faccc7..7e668580e 100644 --- a/Source/ASControlNode.mm +++ b/Source/ASControlNode.mm @@ -295,7 +295,7 @@ - (void)addTarget:(id)target action:(SEL)action forControlEvents:(ASControlNodeE // only show tap-able areas for views with 1 or more addTarget:action: pairs if ([ASControlNode enableHitTestDebug] && _debugHighlightOverlay == nil) { - ASPerformBlockOnMainThread(^{ + dispatch_async(dispatch_get_main_queue(), ^{ // add a highlight overlay node with area of ASControlNode + UIEdgeInsets self.clipsToBounds = NO; _debugHighlightOverlay = [[ASImageNode alloc] init]; From 4ce6669a867b6f85a787000db21e9d989af57c0d Mon Sep 17 00:00:00 2001 From: Garrett Moon Date: Thu, 30 Aug 2018 15:08:58 -0700 Subject: [PATCH 2/2] Add comments, good call @nguyenhuy --- Source/ASControlNode.mm | 2 ++ Source/ASImageNode.mm | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Source/ASControlNode.mm b/Source/ASControlNode.mm index 7e668580e..1256d2d62 100644 --- a/Source/ASControlNode.mm +++ b/Source/ASControlNode.mm @@ -295,6 +295,8 @@ - (void)addTarget:(id)target action:(SEL)action forControlEvents:(ASControlNodeE // only show tap-able areas for views with 1 or more addTarget:action: pairs if ([ASControlNode enableHitTestDebug] && _debugHighlightOverlay == nil) { + // do not use ASPerformBlockOnMainThread here, if it performs the block synchronously it will continue + // holding the lock while calling addSubnode. dispatch_async(dispatch_get_main_queue(), ^{ // add a highlight overlay node with area of ASControlNode + UIEdgeInsets self.clipsToBounds = NO; diff --git a/Source/ASImageNode.mm b/Source/ASImageNode.mm index b8d249aee..f98356d67 100644 --- a/Source/ASImageNode.mm +++ b/Source/ASImageNode.mm @@ -251,6 +251,8 @@ - (void)_locked_setImage:(UIImage *)image // For debugging purposes we don't care about locking for now if ([ASImageNode shouldShowImageScalingOverlay] && _debugLabelNode == nil) { + // do not use ASPerformBlockOnMainThread here, if it performs the block synchronously it will continue + // holding the lock while calling addSubnode. dispatch_async(dispatch_get_main_queue(), ^{ _debugLabelNode = [[ASTextNode alloc] init]; _debugLabelNode.layerBacked = YES;