use lock to avoid crash when image might be changed during the trait collection change (#1651)

This commit is contained in:
vovasty
2019-08-30 12:45:58 -07:00
committed by GitHub
parent 0cd5561fd6
commit 4d6532ccc8
+2 -2
View File
@@ -756,6 +756,7 @@ static ASWeakMap<ASImageNodeContentsKey *, UIImage *> *cache = nil;
[super asyncTraitCollectionDidChangeWithPreviousTraitCollection:previousTraitCollection];
if (AS_AVAILABLE_IOS_TVOS(12, 10)) {
__instanceLock__.lock();
// update image if userInterfaceStyle was changed (dark mode)
if (_image != nil && self.primitiveTraitCollection.userInterfaceStyle != previousTraitCollection.userInterfaceStyle) {
UITraitCollection *tc = [UITraitCollection traitCollectionWithUserInterfaceStyle:self.primitiveTraitCollection.userInterfaceStyle];
@@ -764,9 +765,8 @@ static ASWeakMap<ASImageNodeContentsKey *, UIImage *> *cache = nil;
if ( updatedImage != nil ) {
_image = updatedImage;
}
// trigger needs display anyway, cause image might be dynamic itself (e.g. dynamic tint color)
[self setNeedsDisplay];
}
__instanceLock__.unlock();
}
}