Handle double SurfaceHandler#stop call (#37716)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/37716

We call `surfaceHandler.stop` both from `SurfaceHandlerBinding` as well as `Binding`. Since we don't check asserts in production, the second one should generally be a no-op, but may be causing a crash due to incorrectly de-referencing a unique_ptr.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D46441620

fbshipit-source-id: e93b9722fd717947ebf772f545f692c2e31f816e
This commit is contained in:
Pieter De Baets
2023-06-08 06:51:21 -07:00
committed by Facebook GitHub Bot
parent 3221f37ea1
commit 6a710670f0
2 changed files with 14 additions and 12 deletions
@@ -108,7 +108,9 @@ void SurfaceHandler::stop() const noexcept {
// mounted views, so we need to commit an empty tree to trigger all
// side-effects (including destroying and removing mounted views).
react_native_assert(shadowTree && "`shadowTree` must not be null.");
shadowTree->commitEmptyTree();
if (shadowTree) {
shadowTree->commitEmptyTree();
}
}
void SurfaceHandler::setDisplayMode(DisplayMode displayMode) const noexcept {
@@ -231,19 +231,19 @@ ShadowTree::Unique UIManager::stopSurface(SurfaceId surfaceId) const {
// Waiting for all concurrent commits to be finished and unregistering the
// `ShadowTree`.
auto shadowTree = getShadowTreeRegistry().remove(surfaceId);
if (shadowTree) {
// We execute JavaScript/React part of the process at the very end to
// minimize any visible side-effects of stopping the Surface. Any possible
// commits from the JavaScript side will not be able to reference a
// `ShadowTree` and will fail silently.
runtimeExecutor_([=](jsi::Runtime &runtime) {
SurfaceRegistryBinding::stopSurface(runtime, surfaceId);
});
// We execute JavaScript/React part of the process at the very end to minimize
// any visible side-effects of stopping the Surface. Any possible commits from
// the JavaScript side will not be able to reference a `ShadowTree` and will
// fail silently.
runtimeExecutor_([=](jsi::Runtime &runtime) {
SurfaceRegistryBinding::stopSurface(runtime, surfaceId);
});
if (leakChecker_) {
leakChecker_->stopSurface(surfaceId);
if (leakChecker_) {
leakChecker_->stopSurface(surfaceId);
}
}
return shadowTree;
}