From 0b9763cec500bea6ea46e47ccc9bff2ec018fa26 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Tue, 12 Nov 2024 13:44:51 -0800 Subject: [PATCH] [Impeller] prevent no-op backend from throwing exceptions during image decoding (flutter/engine#56522) This preveents errors reported in some g3 test cases. --- .../flutter/lib/ui/painting/image_decoder_impeller.cc | 7 +++++++ .../src/flutter/lib/ui/painting/multi_frame_codec.cc | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/engine/src/flutter/lib/ui/painting/image_decoder_impeller.cc b/engine/src/flutter/lib/ui/painting/image_decoder_impeller.cc index 6a1118954a9..a73310c492b 100644 --- a/engine/src/flutter/lib/ui/painting/image_decoder_impeller.cc +++ b/engine/src/flutter/lib/ui/painting/image_decoder_impeller.cc @@ -519,6 +519,13 @@ void ImageDecoderImpeller::Decode(fml::RefPtr descriptor, result, supports_wide_gamut = supports_wide_gamut_, // gpu_disabled_switch = gpu_disabled_switch_]() { +#if FML_OS_IOS_SIMULATOR + // No-op backend. + if (!context) { + return; + } +#endif // FML_OS_IOS_SIMULATOR + if (!context) { result(nullptr, "No Impeller context is available"); return; diff --git a/engine/src/flutter/lib/ui/painting/multi_frame_codec.cc b/engine/src/flutter/lib/ui/painting/multi_frame_codec.cc index 1521c535fd9..f05ff111236 100644 --- a/engine/src/flutter/lib/ui/painting/multi_frame_codec.cc +++ b/engine/src/flutter/lib/ui/painting/multi_frame_codec.cc @@ -190,6 +190,17 @@ void MultiFrameCodec::State::GetNextFrameAndInvokeCallback( const std::shared_ptr& gpu_disable_sync_switch, size_t trace_id, const std::shared_ptr& impeller_context) { +#if FML_OS_IOS_SIMULATOR + // Noop backend. + if (!resourceContext && !impeller_context) { + ui_task_runner->PostTask( + fml::MakeCopyable([callback = std::move(callback)]() { + // must be destroyed on UI thread. + })); + return; + } +#endif // FML_OS_IOS_SIMULATOR + fml::RefPtr image = nullptr; int duration = 0; sk_sp dlImage;