Skip to content

Commit b4a04cc

Browse files
author
Jonah Williams
authored
[Impeller] fix crash when loading shader before AiksContext is initialized. (#165071)
If the aiks context isn't initialized, we will create one on the fly which can actually crash on the GLES backend. Add a check if the context is already initialized and cancel precaching of the shader which triggers this crash. The precache is only a performance improvement and is not critical for usability. Fixes flutter/flutter#164757
1 parent a7a4d0b commit b4a04cc

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

engine/src/flutter/shell/common/rasterizer.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,9 @@ sk_sp<SkImage> Rasterizer::ConvertToRasterImage(sk_sp<SkImage> image) {
457457
// |SnapshotDelegate|
458458
void Rasterizer::CacheRuntimeStage(
459459
const std::shared_ptr<impeller::RuntimeStage>& runtime_stage) {
460-
snapshot_controller_->CacheRuntimeStage(runtime_stage);
460+
if (snapshot_controller_) {
461+
snapshot_controller_->CacheRuntimeStage(runtime_stage);
462+
}
461463
}
462464

463465
fml::Milliseconds Rasterizer::GetFrameBudget() const {

engine/src/flutter/shell/common/rasterizer.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,15 @@ class Rasterizer final : public SnapshotDelegate,
670670
return surface_;
671671
}
672672

673+
// |SnapshotController::Delegate|
674+
bool IsAiksContextInitialized() const override {
675+
#if IMPELLER_SUPPORTS_RENDERING
676+
return surface_ && surface_->GetAiksContext();
677+
#else
678+
return false;
679+
#endif
680+
}
681+
673682
// |SnapshotController::Delegate|
674683
std::shared_ptr<impeller::AiksContext> GetAiksContext() const override {
675684
#if IMPELLER_SUPPORTS_RENDERING

engine/src/flutter/shell/common/rasterizer_unittests.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@ TEST(RasterizerTest, create) {
135135
EXPECT_TRUE(rasterizer != nullptr);
136136
}
137137

138+
TEST(RasterizerTest, isAiksContextInitialized) {
139+
NiceMock<MockDelegate> delegate;
140+
Settings settings;
141+
ON_CALL(delegate, GetSettings()).WillByDefault(ReturnRef(settings));
142+
auto rasterizer = std::make_shared<Rasterizer>(delegate);
143+
144+
EXPECT_TRUE(rasterizer != nullptr);
145+
std::shared_ptr<SnapshotController::Delegate> snapshot_delegate = rasterizer;
146+
147+
EXPECT_FALSE(snapshot_delegate->IsAiksContextInitialized());
148+
}
149+
138150
static std::unique_ptr<FrameTimingsRecorder> CreateFinishedBuildRecorder(
139151
fml::TimePoint timestamp) {
140152
std::unique_ptr<FrameTimingsRecorder> recorder =

engine/src/flutter/shell/common/snapshot_controller.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class SnapshotController {
2424
public:
2525
virtual ~Delegate() = default;
2626
virtual const std::unique_ptr<Surface>& GetSurface() const = 0;
27+
virtual bool IsAiksContextInitialized() const = 0;
2728
virtual std::shared_ptr<impeller::AiksContext> GetAiksContext() const = 0;
2829
virtual const std::unique_ptr<SnapshotSurfaceProducer>&
2930
GetSnapshotSurfaceProducer() const = 0;

engine/src/flutter/shell/common/snapshot_controller_impeller.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,15 @@ sk_sp<DlImage> SnapshotControllerImpeller::MakeRasterSnapshotSync(
146146

147147
void SnapshotControllerImpeller::CacheRuntimeStage(
148148
const std::shared_ptr<impeller::RuntimeStage>& runtime_stage) {
149-
impeller::RuntimeEffectContents runtime_effect;
150-
runtime_effect.SetRuntimeStage(runtime_stage);
149+
if (!GetDelegate().IsAiksContextInitialized()) {
150+
return;
151+
}
151152
auto context = GetDelegate().GetAiksContext();
152153
if (!context) {
153154
return;
154155
}
156+
impeller::RuntimeEffectContents runtime_effect;
157+
runtime_effect.SetRuntimeStage(runtime_stage);
155158
runtime_effect.BootstrapShader(context->GetContentContext());
156159
}
157160

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy