diff --git a/engine/src/flutter/runtime/runtime_controller.cc b/engine/src/flutter/runtime/runtime_controller.cc index e7a8ab5253..b7566a10a0 100644 --- a/engine/src/flutter/runtime/runtime_controller.cc +++ b/engine/src/flutter/runtime/runtime_controller.cc @@ -78,6 +78,13 @@ RuntimeController::~RuntimeController() { } } +bool RuntimeController::IsRootIsolateRunning() const { + if (root_isolate_) { + return root_isolate_->GetPhase() == DartIsolate::Phase::Running; + } + return false; +} + std::unique_ptr RuntimeController::Clone() const { return std::unique_ptr(new RuntimeController( client_, // diff --git a/engine/src/flutter/runtime/runtime_controller.h b/engine/src/flutter/runtime/runtime_controller.h index 326c517f31..fb01847a91 100644 --- a/engine/src/flutter/runtime/runtime_controller.h +++ b/engine/src/flutter/runtime/runtime_controller.h @@ -46,6 +46,8 @@ class RuntimeController final : public WindowClient { bool NotifyIdle(int64_t deadline); + bool IsRootIsolateRunning() const; + bool DispatchPlatformMessage(fxl::RefPtr message); bool DispatchPointerDataPacket(const PointerDataPacket& packet); diff --git a/engine/src/flutter/shell/common/engine.cc b/engine/src/flutter/shell/common/engine.cc index 3d6fd496d3..d1231b0d09 100644 --- a/engine/src/flutter/shell/common/engine.cc +++ b/engine/src/flutter/shell/common/engine.cc @@ -259,7 +259,8 @@ void Engine::DispatchPlatformMessage( return; } - if (runtime_controller_->DispatchPlatformMessage(std::move(message))) { + if (runtime_controller_->IsRootIsolateRunning() && + runtime_controller_->DispatchPlatformMessage(std::move(message))) { return; }