diff --git a/engine/src/flutter/lib/ui/painting/image_encoding_unittests.cc b/engine/src/flutter/lib/ui/painting/image_encoding_unittests.cc index 0a53ace53ed..1e059d9b58c 100644 --- a/engine/src/flutter/lib/ui/painting/image_encoding_unittests.cc +++ b/engine/src/flutter/lib/ui/painting/image_encoding_unittests.cc @@ -464,13 +464,16 @@ TEST_F(ShellTest, EncodeImageFailsWithoutGPUImpeller) { AddNativeCallback("TurnOffGPU", CREATE_NATIVE_ENTRY(turn_off_gpu)); auto flush_awaiting_tasks = [&](Dart_NativeArguments args) { - task_runners.GetIOTaskRunner()->PostTask([&] { - std::shared_ptr impeller_context = - shell->GetIOManager()->GetImpellerContext(); - // This will cause the stored tasks to overflow and start throwing them - // away. - for (int i = 0; i < impeller::Context::kMaxTasksAwaitingGPU; i++) { - impeller_context->StoreTaskForGPU([] {}, [] {}); + fml::WeakPtr io_manager = shell->GetIOManager(); + task_runners.GetIOTaskRunner()->PostTask([io_manager] { + if (io_manager) { + std::shared_ptr impeller_context = + io_manager->GetImpellerContext(); + // This will cause the stored tasks to overflow and start throwing them + // away. + for (int i = 0; i < impeller::Context::kMaxTasksAwaitingGPU; i++) { + impeller_context->StoreTaskForGPU([] {}, [] {}); + } } }); };