diff --git a/engine/src/flutter/runtime/runtime_controller.cc b/engine/src/flutter/runtime/runtime_controller.cc index 4f23ea78e5..80dfff0452 100644 --- a/engine/src/flutter/runtime/runtime_controller.cc +++ b/engine/src/flutter/runtime/runtime_controller.cc @@ -50,11 +50,12 @@ std::unique_ptr RuntimeController::Spawn( const fml::closure& p_isolate_shutdown_callback, std::shared_ptr p_persistent_isolate_data, fml::WeakPtr io_manager, - fml::WeakPtr image_decoder) const { + fml::WeakPtr image_decoder, + fml::WeakPtr image_generator_registry) const { UIDartState::Context spawned_context{ context_.task_runners, context_.snapshot_delegate, std::move(io_manager), context_.unref_queue, - std::move(image_decoder), context_.image_generator_registry, + std::move(image_decoder), std::move(image_generator_registry), advisory_script_uri, advisory_script_entrypoint, context_.volatile_path_tracker}; auto result = diff --git a/engine/src/flutter/runtime/runtime_controller.h b/engine/src/flutter/runtime/runtime_controller.h index 57d24b642c..6f476cbe3d 100644 --- a/engine/src/flutter/runtime/runtime_controller.h +++ b/engine/src/flutter/runtime/runtime_controller.h @@ -104,7 +104,8 @@ class RuntimeController : public PlatformConfigurationClient { const fml::closure& isolate_shutdown_callback, std::shared_ptr persistent_isolate_data, fml::WeakPtr io_manager, - fml::WeakPtr image_decoder) const; + fml::WeakPtr image_decoder, + fml::WeakPtr image_generator_registry) const; // |PlatformConfigurationClient| ~RuntimeController() override; @@ -555,6 +556,10 @@ class RuntimeController : public PlatformConfigurationClient { return context_.snapshot_delegate; } + std::weak_ptr GetRootIsolate() const { + return root_isolate_; + } + protected: /// Constructor for Mocks. RuntimeController(RuntimeDelegate& p_client, TaskRunners task_runners); diff --git a/engine/src/flutter/shell/common/engine.cc b/engine/src/flutter/shell/common/engine.cc index 68c8fa3626..fed5bbd28b 100644 --- a/engine/src/flutter/shell/common/engine.cc +++ b/engine/src/flutter/shell/common/engine.cc @@ -119,16 +119,16 @@ std::unique_ptr Engine::Spawn( /*font_collection=*/font_collection_, /*runtime_controller=*/nullptr); result->runtime_controller_ = runtime_controller_->Spawn( - *result, // runtime delegate - settings.advisory_script_uri, // advisory script uri - settings.advisory_script_entrypoint, // advisory script entrypoint - settings.idle_notification_callback, // idle notification callback - settings.isolate_create_callback, // isolate create callback - settings.isolate_shutdown_callback, // isolate shutdown callback - settings.persistent_isolate_data, // persistent isolate data - io_manager, // io_manager - result->GetImageDecoderWeakPtr() // imageDecoder - ); + /*p_client=*/*result, + /*advisory_script_uri=*/settings.advisory_script_uri, + /*advisory_script_entrypoint=*/settings.advisory_script_entrypoint, + /*idle_notification_callback=*/settings.idle_notification_callback, + /*isolate_create_callback=*/settings.isolate_create_callback, + /*isolate_shutdown_callback=*/settings.isolate_shutdown_callback, + /*persistent_isolate_data=*/settings.persistent_isolate_data, + /*io_manager=*/io_manager, + /*image_decoder=*/result->GetImageDecoderWeakPtr(), + /*image_generator_registry=*/result->GetImageGeneratorRegistry()); result->initial_route_ = initial_route; return result; } diff --git a/engine/src/flutter/shell/common/shell_unittests.cc b/engine/src/flutter/shell/common/shell_unittests.cc index bee55ab690..96dae42638 100644 --- a/engine/src/flutter/shell/common/shell_unittests.cc +++ b/engine/src/flutter/shell/common/shell_unittests.cc @@ -3125,6 +3125,54 @@ TEST_F(ShellTest, IOManagerInSpawnedShellIsNotNullAfterParentShellDestroyed) { DestroyShell(std::move(spawn)); } +TEST_F(ShellTest, ImageGeneratorRegistryNotNullAfterParentShellDestroyed) { + auto settings = CreateSettingsForFixture(); + auto shell = CreateShell(settings); + ASSERT_TRUE(ValidateShell(shell.get())); + + std::unique_ptr spawn; + + PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell, &settings, + &spawn] { + auto second_configuration = RunConfiguration::InferFromSettings(settings); + ASSERT_TRUE(second_configuration.IsValid()); + second_configuration.SetEntrypoint("emptyMain"); + const std::string initial_route("/foo"); + MockPlatformViewDelegate platform_view_delegate; + auto child = shell->Spawn( + std::move(second_configuration), initial_route, + [&platform_view_delegate](Shell& shell) { + auto result = std::make_unique( + platform_view_delegate, shell.GetTaskRunners()); + ON_CALL(*result, CreateRenderingSurface()) + .WillByDefault(::testing::Invoke( + [] { return std::make_unique(); })); + return result; + }, + [](Shell& shell) { return std::make_unique(shell); }); + spawn = std::move(child); + }); + + PostSync(spawn->GetTaskRunners().GetUITaskRunner(), [&spawn] { + std::shared_ptr isolate = + spawn->GetEngine()->GetRuntimeController()->GetRootIsolate().lock(); + ASSERT_TRUE(isolate); + ASSERT_TRUE(isolate->GetImageGeneratorRegistry()); + }); + + // Destroy the parent shell. + DestroyShell(std::move(shell)); + + PostSync(spawn->GetTaskRunners().GetUITaskRunner(), [&spawn] { + std::shared_ptr isolate = + spawn->GetEngine()->GetRuntimeController()->GetRootIsolate().lock(); + ASSERT_TRUE(isolate); + ASSERT_TRUE(isolate->GetImageGeneratorRegistry()); + }); + // Destroy the child shell. + DestroyShell(std::move(spawn)); +} + TEST_F(ShellTest, UpdateAssetResolverByTypeReplaces) { ASSERT_FALSE(DartVMRef::IsInstanceRunning()); Settings settings = CreateSettingsForFixture();