From 80c5b5d61965a09e4ee970f1c880f696e3c71f60 Mon Sep 17 00:00:00 2001 From: wwwcg Date: Tue, 24 Sep 2024 11:33:20 +0800 Subject: [PATCH] fix(ios): nullptr exception of engine resources in rare scenarios (#4046) --- framework/ios/base/executors/HippyJSExecutor.mm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/framework/ios/base/executors/HippyJSExecutor.mm b/framework/ios/base/executors/HippyJSExecutor.mm index b646c3f67b6..2bc0ab487f7 100644 --- a/framework/ios/base/executors/HippyJSExecutor.mm +++ b/framework/ios/base/executors/HippyJSExecutor.mm @@ -661,7 +661,11 @@ - (void)executeBlockOnJavaScriptQueue:(dispatch_block_t)block { return; } } - auto engine = [[HippyJSEnginesMapper defaultInstance] JSEngineResourceForKey:self.enginekey]->GetEngine(); + std::shared_ptr engineRsc = [[HippyJSEnginesMapper defaultInstance] JSEngineResourceForKey:self.enginekey]; + if (!engineRsc) { + return; + } + auto engine = engineRsc->GetEngine(); if (engine) { auto runner = engine->GetJsTaskRunner(); if (footstone::Worker::IsTaskRunning() && runner == footstone::runner::TaskRunner::GetCurrentTaskRunner()) { @@ -679,7 +683,11 @@ - (void)executeAsyncBlockOnJavaScriptQueue:(dispatch_block_t)block { return; } } - auto engine = [[HippyJSEnginesMapper defaultInstance] JSEngineResourceForKey:self.enginekey]->GetEngine(); + std::shared_ptr engineRsc = [[HippyJSEnginesMapper defaultInstance] JSEngineResourceForKey:self.enginekey]; + if (!engineRsc) { + return; + } + auto engine = engineRsc->GetEngine(); if (engine) { engine->GetJsTaskRunner()->PostTask(block); }