Commit 42d98b5
Fix SIGSEGV in animation backend callback by capturing weak_ptr (#56130)
Summary:
Pull Request resolved: #56130
The NativeAnimatedNodesManager crashes with SIGSEGV (for example in mid 2e1610331cf5e285e285a2af191fe6f3, but there are also others with similar stacks). When the
manager is destroyed on the JS thread while the Choreographer thread is still
firing animation frames, `pullAnimationMutations` runs on a freed object, because we captured it as a raw `this` pointer. To fix this I added a `weak_from_this` call there, to ensure the manager is still around.
One thing about this issue is that it looks like it should also happen for c++ Animated without the Animation Backend, as right after this call we have:
```
if (startOnRenderCallback_) {
startOnRenderCallback_([this]() { onRender(); }, isAsync);
stopRenderCallbackIfNeeded(false);
}
}
```
which also captures `this`.
On android it is not a problem though, as Android doesn't use `startOnRenderCallback_` (it only relies on `driveCxxAnimations` which is safe). On iOS it seems to be safe due to D91236980, as it adds locking a pointer to the `_nativeAnimatedNodesManagerProvider` (which owns `nativeAnimatedNodesManager`) before calling the scheduled callback.
## Changelog:
[General] [Added] - Add enable_shared_from_this to `NativeAnimatedNodesManager`
[General] [Changed] - Use weak_ptr when calling pullAnimationMutations in a callback scheduled with the Animation Backend
Reviewed By: zeyap
Differential Revision: D97101348
fbshipit-source-id: acdad4e689d72b73a945b49907350c68a67729ab1 parent 0b1ce70 commit 42d98b5
File tree
2 files changed
+8
-4
lines changed- packages/react-native/ReactCommon/react/renderer/animated
2 files changed
+8
-4
lines changedLines changed: 7 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
552 | 552 | | |
553 | 553 | | |
554 | 554 | | |
555 | | - | |
556 | | - | |
557 | | - | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
558 | 562 | | |
559 | 563 | | |
560 | 564 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| |||
0 commit comments