Skip to content

Commit 40043a1

Browse files
JoshuaGrossfacebook-github-bot
authored andcommitted
Animations: attempt to mitigate crashes in T43628589
Summary: Trying to mitigate animation-related crashes in T43628589. Clues: all the crashes are off the main thread, and most operations in this class happen explicitly in blocks executed on the main thread. I think there's a category of race conditions caused by animations not being allocated yet when this code runs / being deallocated as it's running. We shouldn't need to add locks if everything just runs on the main thread. Reviewed By: PeteTheHeat Differential Revision: D15924310 fbshipit-source-id: d82f5434e53fd394c4a7548d52f59a0f63961779
1 parent 2a4882e commit 40043a1

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

Libraries/NativeAnimation/RCTNativeAnimatedModule.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,14 @@ - (void)setBridge:(RCTBridge *)bridge
8787
[self addOperationBlock:^(RCTNativeAnimatedNodesManager *nodesManager) {
8888
[nodesManager startAnimatingNode:animationId nodeTag:nodeTag config:config endCallback:callBack];
8989
}];
90-
if ([_nodesManager isNodeManagedByFabric:nodeTag]) {
91-
_animIdIsManagedByFabric[animationId] = @YES;
92-
[self flushOperationQueues];
93-
}
90+
__weak RCTNativeAnimatedModule *weakSelf = self;
91+
RCTExecuteOnMainQueue(^{
92+
__strong RCTNativeAnimatedModule *strongSelf = weakSelf;
93+
if (strongSelf && [strongSelf->_nodesManager isNodeManagedByFabric:nodeTag]) {
94+
strongSelf->_animIdIsManagedByFabric[animationId] = @YES;
95+
[strongSelf flushOperationQueues];
96+
}
97+
});
9498
}
9599

96100
RCT_EXPORT_METHOD(stopAnimation:(nonnull NSNumber *)animationId)

Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ - (instancetype)initWithBridge:(nonnull RCTBridge *)bridge
5353
- (BOOL)isNodeManagedByFabric:(nonnull NSNumber *)tag
5454
{
5555
RCTAnimatedNode *node = _animationNodes[tag];
56-
return [node isManagedByFabric];
56+
if (node) {
57+
return [node isManagedByFabric];
58+
}
59+
return false;
5760
}
5861

5962
#pragma mark -- Graph

0 commit comments

Comments
 (0)