From 556edafbb4a27e9a252040b3fb28ced2c0949500 Mon Sep 17 00:00:00 2001 From: Tomek Zawadzki Date: Tue, 3 Dec 2024 10:30:08 +0100 Subject: [PATCH] Clear `operationsInBatch_` before terminating UI runtime (#6779) ## Summary This PR fixes the following crash that happens during a reload due to `jsi::Value` outliving the UI runtime. The offending `jsi::Value` comes from `operationsInBatch_` inside `ReanimatedModuleProxy` (formerly `NativeReanimatedModule`. In `~ReanimatedModuleProxy` we manually clear data structures containing `jsi::Value` prior to resetting `uiWorkletRuntime_` which effectively terminates the runtimes. It looks like we forgot about `operationsInBatch_`. Screenshot 2024-12-02 at 13 00 08 ## Test plan 1. Launch FabricExample app 2. Reload the app several times 3. Repeat steps 1 and 2 several times --- .../cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp b/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp index 12b4b22fe8bd..2be3ac637e8d 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp +++ b/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp @@ -198,6 +198,9 @@ ReanimatedModuleProxy::~ReanimatedModuleProxy() { // runtime, so they have to go away before we tear down the runtime eventHandlerRegistry_.reset(); frameCallbacks_.clear(); +#ifdef RCT_NEW_ARCH_ENABLED + operationsInBatch_.clear(); +#endif // RCT_NEW_ARCH_ENABLED uiWorkletRuntime_.reset(); }