Skip to content

Commit 7764b5c

Browse files
authored
Only call destruction_callback if non-null (flutter#24845)
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#76881. While this prevents the crash, it does not fix the underlying issue.
1 parent 2441c47 commit 7764b5c

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

shell/platform/embedder/embedder.cc

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,9 @@ static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(
469469

470470
if (!surface) {
471471
FML_LOG(ERROR) << "Could not wrap embedder supplied render texture.";
472-
texture->destruction_callback(texture->user_data);
472+
if (texture->destruction_callback) {
473+
texture->destruction_callback(texture->user_data);
474+
}
473475
return nullptr;
474476
}
475477

@@ -512,7 +514,9 @@ static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(
512514

513515
if (!surface) {
514516
FML_LOG(ERROR) << "Could not wrap embedder supplied frame-buffer.";
515-
framebuffer->destruction_callback(framebuffer->user_data);
517+
if (framebuffer->destruction_callback) {
518+
framebuffer->destruction_callback(framebuffer->user_data);
519+
}
516520
return nullptr;
517521
}
518522
return surface;
@@ -537,7 +541,9 @@ static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(
537541
captures->user_data = software->user_data;
538542
auto release_proc = [](void* pixels, void* context) {
539543
auto captures = reinterpret_cast<Captures*>(context);
540-
captures->destruction_callback(captures->user_data);
544+
if (captures->destruction_callback) {
545+
captures->destruction_callback(captures->user_data);
546+
}
541547
};
542548

543549
auto surface = SkSurface::MakeRasterDirectReleaseProc(
@@ -551,7 +557,9 @@ static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(
551557
if (!surface) {
552558
FML_LOG(ERROR)
553559
<< "Could not wrap embedder supplied software render buffer.";
554-
software->destruction_callback(software->user_data);
560+
if (software->destruction_callback) {
561+
software->destruction_callback(software->user_data);
562+
}
555563
return nullptr;
556564
}
557565
return surface;

0 commit comments

Comments
 (0)