diff --git a/shell/platform/fuchsia/flutter/engine.cc b/shell/platform/fuchsia/flutter/engine.cc index 62ba6362bebbe..58d4f764c8407 100644 --- a/shell/platform/fuchsia/flutter/engine.cc +++ b/shell/platform/fuchsia/flutter/engine.cc @@ -575,6 +575,20 @@ void Engine::Initialize( Engine::~Engine() { shell_.reset(); + + // Destroy rendering objects on the raster thread. + fml::AutoResetWaitableEvent view_embedder_latch; + thread_host_.raster_thread->GetTaskRunner()->PostTask( + fml::MakeCopyable([this, &view_embedder_latch]() mutable { + flatland_view_embedder_.reset(); + external_view_embedder_.reset(); + surface_producer_.reset(); + flatland_connection_.reset(); + session_connection_.reset(); + + view_embedder_latch.Signal(); + })); + view_embedder_latch.Wait(); } std::optional Engine::GetEngineReturnCode() const { diff --git a/shell/platform/fuchsia/flutter/engine.h b/shell/platform/fuchsia/flutter/engine.h index 86fbc1ecf8873..ddf84eac13b26 100644 --- a/shell/platform/fuchsia/flutter/engine.h +++ b/shell/platform/fuchsia/flutter/engine.h @@ -90,16 +90,14 @@ class Engine final { const std::string thread_label_; flutter::ThreadHost thread_host_; - std::optional surface_producer_; - - // Gfx specific classes. fuchsia::ui::views::ViewToken view_token_; - std::shared_ptr session_connection_; - std::shared_ptr external_view_embedder_; - - // Flatland specific classes. fuchsia::ui::views::ViewCreationToken view_creation_token_; - std::shared_ptr flatland_connection_; + std::shared_ptr + session_connection_; // Must come before surface_producer_ + std::shared_ptr + flatland_connection_; // Must come before surface_producer_ + std::optional surface_producer_; + std::shared_ptr external_view_embedder_; std::shared_ptr flatland_view_embedder_; scenic::ViewRefPair view_ref_pair_;