Skip to content

Commit

Permalink
Only call destruction_callback if non-null (flutter#24845)
Browse files Browse the repository at this point in the history
In MakeSkSurfaceFromBackingStore and other places in embedder.cc, we
call a texture or framebuffer destruction callback without first
verifying it's non-null. This adds a check before such calls.

Currently fl_renderer_gl_create_backing_store() in the Linux GTK
embedder and ExternalTextureGL::PopulateTexture() in the Windows
embedder either explicitly or implicitly set a null destruction
callback.

This prevents a crash reported when running under OpenGL ES 2.0 reported
in flutter/flutter#76881.

While this prevents the crash, it does not fix the underlying issue.
  • Loading branch information
cbracken authored and chriscraws committed Mar 22, 2021
1 parent c4020d8 commit 8d3ce1d
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions shell/platform/embedder/embedder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,9 @@ static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(

if (!surface) {
FML_LOG(ERROR) << "Could not wrap embedder supplied render texture.";
texture->destruction_callback(texture->user_data);
if (texture->destruction_callback) {
texture->destruction_callback(texture->user_data);
}
return nullptr;
}

Expand Down Expand Up @@ -512,7 +514,9 @@ static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(

if (!surface) {
FML_LOG(ERROR) << "Could not wrap embedder supplied frame-buffer.";
framebuffer->destruction_callback(framebuffer->user_data);
if (framebuffer->destruction_callback) {
framebuffer->destruction_callback(framebuffer->user_data);
}
return nullptr;
}
return surface;
Expand All @@ -537,7 +541,9 @@ static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(
captures->user_data = software->user_data;
auto release_proc = [](void* pixels, void* context) {
auto captures = reinterpret_cast<Captures*>(context);
captures->destruction_callback(captures->user_data);
if (captures->destruction_callback) {
captures->destruction_callback(captures->user_data);
}
};

auto surface = SkSurface::MakeRasterDirectReleaseProc(
Expand All @@ -551,7 +557,9 @@ static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(
if (!surface) {
FML_LOG(ERROR)
<< "Could not wrap embedder supplied software render buffer.";
software->destruction_callback(software->user_data);
if (software->destruction_callback) {
software->destruction_callback(software->user_data);
}
return nullptr;
}
return surface;
Expand Down

0 comments on commit 8d3ce1d

Please sign in to comment.