mirror of
https://github.com/openharmony/ace_ace_engine.git
synced 2026-07-19 14:43:36 -04:00
use weak to avoid use nativeEngine after destroy
Signed-off-by: zcdqs <junfeng.lijunfeng@huawei.com> Change-Id: I0073eaebfdaaa728ad09b2778664ad48df388413
This commit is contained in:
@@ -758,17 +758,23 @@ void JsiDeclarativeEngine::SetPostTask(NativeEngine* nativeEngine)
|
||||
{
|
||||
LOGI("SetPostTask");
|
||||
auto weakDelegate = AceType::WeakClaim(AceType::RawPtr(engineInstance_->GetDelegate()));
|
||||
auto&& postTask = [weakDelegate, nativeEngine = nativeEngine_, id = instanceId_](bool needSync) {
|
||||
auto&& postTask = [weakDelegate, weakEngine = AceType::WeakClaim(this), id = instanceId_](bool needSync) {
|
||||
auto delegate = weakDelegate.Upgrade();
|
||||
if (delegate == nullptr) {
|
||||
LOGE("delegate is nullptr");
|
||||
return;
|
||||
}
|
||||
delegate->PostJsTask([nativeEngine, needSync, id]() {
|
||||
ContainerScope scope(id);
|
||||
delegate->PostJsTask([weakEngine, needSync, id]() {
|
||||
auto jsEngine = weakEngine.Upgrade();
|
||||
if (jsEngine == nullptr) {
|
||||
LOGW("jsEngine is nullptr");
|
||||
return;
|
||||
}
|
||||
auto nativeEngine = jsEngine->GetNativeEngine();
|
||||
if (nativeEngine == nullptr) {
|
||||
return;
|
||||
}
|
||||
ContainerScope scope(id);
|
||||
nativeEngine->Loop(LOOP_NOWAIT, needSync);
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user