diff --git a/adapter/common/cpp/flutter_window.cpp b/adapter/common/cpp/flutter_window.cpp index a2581c69b73..d6f0777631f 100644 --- a/adapter/common/cpp/flutter_window.cpp +++ b/adapter/common/cpp/flutter_window.cpp @@ -40,6 +40,15 @@ FlutterWindow::FlutterWindow(int32_t instanceId) : instanceId_(instanceId) {} FlutterWindow::~FlutterWindow() {} +void FlutterWindow::Destroy() +{ + auto window = flutter::WindowManager::GetWindow(instanceId_); + if (window != nullptr) { + window->SetBeginFrameCallback(nullptr); + } + vsyncCallbacks_.clear(); +} + void FlutterWindow::RequestFrame() { auto window = flutter::WindowManager::GetWindow(instanceId_); diff --git a/adapter/common/cpp/flutter_window.h b/adapter/common/cpp/flutter_window.h index ad5dc9773f5..36b9abd696d 100644 --- a/adapter/common/cpp/flutter_window.h +++ b/adapter/common/cpp/flutter_window.h @@ -28,6 +28,8 @@ public: explicit FlutterWindow(int32_t instanceId); ~FlutterWindow() override; + void Destroy() override; + // Platform window interface void RequestFrame() override; void RegisterVsyncCallback(AceVsyncCallback&& callback) override; diff --git a/adapter/preview/entrance/flutter_window.cpp b/adapter/preview/entrance/flutter_window.cpp index 9400abaa230..8230cc9c1da 100644 --- a/adapter/preview/entrance/flutter_window.cpp +++ b/adapter/preview/entrance/flutter_window.cpp @@ -61,7 +61,9 @@ void FlutterWindow::SetRootRenderNode(const RefPtr& root) {} void FlutterWindow::OnVsyncCallback(uint64_t timeStampNanos) { for (const auto& vsyncCallback : vsyncCallbacks_) { - vsyncCallback(timeStampNanos, 0); + if (vsyncCallback) { + vsyncCallback(timeStampNanos, 0); + } } } diff --git a/frameworks/bridge/declarative_frontend/engine/quickjs/qjs_declarative_engine.cpp b/frameworks/bridge/declarative_frontend/engine/quickjs/qjs_declarative_engine.cpp index a1e73c06161..a96d04490df 100644 --- a/frameworks/bridge/declarative_frontend/engine/quickjs/qjs_declarative_engine.cpp +++ b/frameworks/bridge/declarative_frontend/engine/quickjs/qjs_declarative_engine.cpp @@ -37,7 +37,9 @@ QJSDeclarativeEngine::~QJSDeclarativeEngine() delete nativeEngine_; } #endif - JS_RunGC(engineInstance_->GetQJSRuntime()); + if (engineInstance_ && engineInstance_->GetQJSRuntime()) { + JS_RunGC(engineInstance_->GetQJSRuntime()); + } } bool QJSDeclarativeEngine::Initialize(const RefPtr& delegate) diff --git a/frameworks/bridge/js_frontend/engine/quickjs/qjs_engine.cpp b/frameworks/bridge/js_frontend/engine/quickjs/qjs_engine.cpp index 8a7062a4d63..092d0de8bc7 100644 --- a/frameworks/bridge/js_frontend/engine/quickjs/qjs_engine.cpp +++ b/frameworks/bridge/js_frontend/engine/quickjs/qjs_engine.cpp @@ -3062,8 +3062,9 @@ QjsEngine::~QjsEngine() nativeEngine_->CancelCheckUVLoop(); delete nativeEngine_; } - ACE_DCHECK(engineInstance_); - JS_RunGC(engineInstance_->GetQjsRuntime()); + if (engineInstance_ && engineInstance_->GetQjsRuntime()) { + JS_RunGC(engineInstance_->GetQjsRuntime()); + } } void QjsEngine::GetLoadOptions(std::string& optionStr, bool isMainPage, const RefPtr& page) diff --git a/frameworks/bridge/pa_backend/engine/quickjs/qjs_pa_engine.cpp b/frameworks/bridge/pa_backend/engine/quickjs/qjs_pa_engine.cpp index 56fff8fb737..a4c557ae30c 100644 --- a/frameworks/bridge/pa_backend/engine/quickjs/qjs_pa_engine.cpp +++ b/frameworks/bridge/pa_backend/engine/quickjs/qjs_pa_engine.cpp @@ -405,8 +405,9 @@ QjsPaEngine::~QjsPaEngine() if (nativeEngine_ != nullptr) { delete nativeEngine_; } - ACE_DCHECK(engineInstance_); - JS_RunGC(engineInstance_->GetQjsRuntime()); + if (engineInstance_ && engineInstance_->GetQjsRuntime()) { + JS_RunGC(engineInstance_->GetQjsRuntime()); + } } inline int32_t GetJsInt32Val(JSContext* ctx, JSValueConst value) diff --git a/frameworks/core/common/platform_window.h b/frameworks/core/common/platform_window.h index a804cea8554..8dbc5b3d4f0 100644 --- a/frameworks/core/common/platform_window.h +++ b/frameworks/core/common/platform_window.h @@ -36,6 +36,8 @@ public: static std::unique_ptr Create(AceView* aceView); + virtual void Destroy() {}; + // Request next vsync. virtual void RequestFrame() = 0; diff --git a/frameworks/core/common/window.h b/frameworks/core/common/window.h index b6b95a1bf24..728a31a22e2 100644 --- a/frameworks/core/common/window.h +++ b/frameworks/core/common/window.h @@ -34,6 +34,7 @@ public: void Destroy() { + platformWindow_->Destroy(); platformWindow_.reset(); }