Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xcode 13 ASLoadFrameworkInitializer dead lock fix on running unit test #2032

Merged
merged 7 commits into from
Dec 3, 2021
11 changes: 9 additions & 2 deletions Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,16 @@ + (void)initialize
}

#if !AS_INITIALIZE_FRAMEWORK_MANUALLY
__attribute__((constructor)) static void ASLoadFrameworkInitializer(void)
__attribute__((constructor)) static void ASLoadFrameworkInitializerOnConstructor(void)
{
ASInitializeFrameworkMainThread();
ASInitializeFrameworkMainThreadOnConstructor();
}
#endif

#if !AS_INITIALIZE_FRAMEWORK_MANUALLY
__attribute__((destructor)) static void ASLoadFrameworkInitializerOnDestructor(void)
{
ASInitializeFrameworkMainThreadOnDestructor();
}
#endif

Expand Down
3 changes: 3 additions & 0 deletions Source/Details/_ASDisplayLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#import <AsyncDisplayKit/ASAssert.h>
#import <AsyncDisplayKit/ASDisplayNode.h>
#import <AsyncDisplayKit/ASDisplayNodeInternal.h>
#import <AsyncDisplayKit/ASInternalHelpers.h>

@implementation _ASDisplayLayer
{
Expand Down Expand Up @@ -125,6 +126,8 @@ + (id)defaultValueForKey:(NSString *)key
return @YES;
} else if ([key isEqualToString:@"opaque"]) {
return @YES;
} else if ([key isEqualToString:@"contentsScale"]) {
return @(ASScreenScale());
} else {
return [super defaultValueForKey:key];
}
Expand Down
3 changes: 2 additions & 1 deletion Source/Private/ASInternalHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

NS_ASSUME_NONNULL_BEGIN

ASDK_EXTERN void ASInitializeFrameworkMainThread(void);
ASDK_EXTERN void ASInitializeFrameworkMainThreadOnConstructor(void);
ASDK_EXTERN void ASInitializeFrameworkMainThreadOnDestructor(void);

ASDK_EXTERN BOOL ASDefaultAllowsGroupOpacity(void);
ASDK_EXTERN BOOL ASDefaultAllowsEdgeAntialiasing(void);
Expand Down
18 changes: 13 additions & 5 deletions Source/Private/ASInternalHelpers.mm
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,19 @@ void _ASInitializeSignpostObservers(void)
}
#endif // AS_SIGNPOST_ENABLE

void ASInitializeFrameworkMainThread(void)
void ASInitializeFrameworkMainThreadOnConstructor(void)
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
ASDisplayNodeCAssertMainThread();
ASNotifyInitialized();
#if AS_SIGNPOST_ENABLE
_ASInitializeSignpostObservers();
#endif
});
}

void ASInitializeFrameworkMainThreadOnDestructor(void)
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Expand All @@ -74,10 +86,6 @@ void ASInitializeFrameworkMainThread(void)
allowsGroupOpacityFromUIKitOrNil = @(layer.allowsGroupOpacity);
allowsEdgeAntialiasingFromUIKitOrNil = @(layer.allowsEdgeAntialiasing);
}
ASNotifyInitialized();
#if AS_SIGNPOST_ENABLE
_ASInitializeSignpostObservers();
#endif
});
}

Expand Down
10 changes: 2 additions & 8 deletions Tests/ASBridgedPropertiesTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,8 @@ - (void)testThatSettingTintColorSetNeedsDisplayOnView
ASDisplayNode *node = [[ASDisplayNode alloc] initWithViewClass:ASBridgedPropertiesTestView.class];
ASBridgedPropertiesTestView *view = (ASBridgedPropertiesTestView *)node.view;
NSUInteger initialSetNeedsDisplayCount = view.setNeedsDisplayCount;
#if AS_AT_LEAST_IOS13
// This is called an extra time on iOS13 for unknown reasons. Need to Investigate.
if (@available(iOS 13.0, *)) {
XCTAssertEqual(initialSetNeedsDisplayCount, 2);
} else {
XCTAssertEqual(initialSetNeedsDisplayCount, 1);
}
#endif

XCTAssertEqual(initialSetNeedsDisplayCount, 1);

ASDispatchSyncOnOtherThread(^{
node.tintColor = UIColor.orangeColor;
Expand Down
2 changes: 1 addition & 1 deletion Tests/ASDisplayNodeTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ - (void)checkValuesMatchDefaults:(ASDisplayNode *)node isLayerBacked:(BOOL)isLay
XCTAssertTrue(CGRectEqualToRect(CGRectZero, node.frame), @"default frame broken %@", hasLoadedView);
XCTAssertTrue(CGPointEqualToPoint(CGPointZero, node.position), @"default position broken %@", hasLoadedView);
XCTAssertEqual((CGFloat)0.0, node.zPosition, @"default zPosition broken %@", hasLoadedView);
XCTAssertEqual(node.isNodeLoaded && !isLayerBacked ? 2.0f : 1.0f, node.contentsScale, @"default contentsScale broken %@", hasLoadedView);
XCTAssertEqual(node.isNodeLoaded && isLayerBacked ? 2.0f : 1.0f, node.contentsScale, @"default contentsScale broken %@", hasLoadedView);
XCTAssertEqual([UIScreen mainScreen].scale, node.contentsScaleForDisplay, @"default contentsScaleForDisplay broken %@", hasLoadedView);
XCTAssertTrue(CATransform3DEqualToTransform(CATransform3DIdentity, node.transform), @"default transform broken %@", hasLoadedView);
XCTAssertTrue(CATransform3DEqualToTransform(CATransform3DIdentity, node.subnodeTransform), @"default subnodeTransform broken %@", hasLoadedView);
Expand Down