From 46120bc38a79556f32d20a0fb0b9da60f79f3ad0 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Tue, 17 Sep 2019 16:40:24 -0700 Subject: [PATCH] Fabric: Using EventBeat::Owner to prevent a crash caused by issuing a bit for already deallocated Scheduler Summary: The concept of `EventBeat::Owner` was introduced in D17128549, this diff implements some missing pieces of that. After the change, AsyncEventEmitter will check the existence of the "owner" (which is EventDispatcher) which guarantees that the rest of the pipeline is still alive (the validity of Runtime is guaranteed by RuntimeExecutor separately). The overall workflow is described in D17128549. Reviewed By: JoshuaGross Differential Revision: D17410738 fbshipit-source-id: a1ae8e09600546874cdc7c622b3d884b71c5b48d --- .../java/com/facebook/react/fabric/jni/AsyncEventBeat.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/AsyncEventBeat.h b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/AsyncEventBeat.h index b0811831704..b566a28d0d3 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/AsyncEventBeat.h +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/AsyncEventBeat.h @@ -41,7 +41,12 @@ class AsyncEventBeat : public EventBeat { } void induce() const override { - runtimeExecutor_([=](jsi::Runtime &runtime) { + runtimeExecutor_([this, ownerBox = ownerBox_](jsi::Runtime &runtime) { + auto owner = ownerBox->owner.lock(); + if (!owner) { + return; + } + this->beat(runtime); }); }