diff --git a/engine/src/flutter/impeller/display_list/aiks_dl_unittests.cc b/engine/src/flutter/impeller/display_list/aiks_dl_unittests.cc index db9bb35ae8..e217d56155 100644 --- a/engine/src/flutter/impeller/display_list/aiks_dl_unittests.cc +++ b/engine/src/flutter/impeller/display_list/aiks_dl_unittests.cc @@ -21,10 +21,12 @@ #include "flutter/testing/testing.h" #include "fml/synchronization/count_down_latch.h" #include "imgui.h" +#include "impeller/base/validation.h" #include "impeller/core/device_buffer.h" #include "impeller/core/device_buffer_descriptor.h" #include "impeller/core/formats.h" #include "impeller/core/texture_descriptor.h" +#include "impeller/display_list/aiks_context.h" #include "impeller/display_list/dl_dispatcher.h" #include "impeller/display_list/dl_image_impeller.h" #include "impeller/geometry/scalar.h" @@ -1104,5 +1106,18 @@ TEST_P(AiksTest, ToImageFromImage) { OpenPlaygroundHere(canvas.Build()); } +TEST_P(AiksTest, DisplayListToTextureAllocationFailure) { + ScopedValidationDisable disable_validations; + DisplayListBuilder builder; + + AiksContext aiks_context(GetContext(), nullptr); + // Use intentionally invalid dimensions that would trigger an allocation + // failure. + auto texture = + DisplayListToTexture(builder.Build(), ISize{0, 0}, aiks_context); + + EXPECT_EQ(texture, nullptr); +} + } // namespace testing } // namespace impeller diff --git a/engine/src/flutter/impeller/display_list/dl_dispatcher.cc b/engine/src/flutter/impeller/display_list/dl_dispatcher.cc index 660737ca0f..11e5e6a844 100644 --- a/engine/src/flutter/impeller/display_list/dl_dispatcher.cc +++ b/engine/src/flutter/impeller/display_list/dl_dispatcher.cc @@ -1309,6 +1309,9 @@ std::shared_ptr DisplayListToTexture( kDefaultColorAttachmentConfig // color_attachment_config ); } + if (!target.IsValid()) { + return nullptr; + } SkIRect sk_cull_rect = SkIRect::MakeWH(size.width, size.height); impeller::FirstPassDispatcher collector( diff --git a/engine/src/flutter/shell/common/snapshot_controller_impeller.cc b/engine/src/flutter/shell/common/snapshot_controller_impeller.cc index 5bfbd2113e..b60f82132e 100644 --- a/engine/src/flutter/shell/common/snapshot_controller_impeller.cc +++ b/engine/src/flutter/shell/common/snapshot_controller_impeller.cc @@ -58,7 +58,7 @@ sk_sp DoMakeRasterSnapshot( const sk_sp& display_list, SkISize size, const SnapshotController::Delegate& delegate) { - // Ensure that the current thread has a rendering context. This must be done + // Ensure that the current thread has a rendering context. This must be done // before calling GetAiksContext because constructing the AiksContext may // invoke graphics APIs. std::unique_ptr pbuffer_surface;