From 1fe241df91e2df8ab6915934b9c290e52b83b1eb Mon Sep 17 00:00:00 2001 From: Garrett Moon Date: Thu, 30 Aug 2018 22:04:40 -0700 Subject: [PATCH] #trivial Shouldn't hold the lock while adding subnodes (#1091) * Shouldn't hold the lock while adding subnodes * Add comments, good call @nguyenhuy --- Source/ASControlNode.mm | 4 +++- Source/ASImageNode.mm | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Source/ASControlNode.mm b/Source/ASControlNode.mm index c04faccc7..1256d2d62 100644 --- a/Source/ASControlNode.mm +++ b/Source/ASControlNode.mm @@ -295,7 +295,9 @@ - (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(^{ + // 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; _debugHighlightOverlay = [[ASImageNode alloc] init]; 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;