Skip to content

Commit b390e73

Browse files
committed
fix(texture): guard render-thread teardown against engine shutdown
The render-thread teardown task posted by UnregisterTexture() captures a raw renderer pointer. If the engine shuts down before the task runs, PostRenderThreadTask() runs it inline and the renderer may already be destroyed, so gl_renderer->OnMakeCurrent() could touch a dangling GL context/renderer. Guard the OnMakeCurrent() call with engine->IsRunning(). UnregisterExternalTexture() stays unconditional: it is null-safe at the embedder boundary (a torn-down engine handle just yields an error return) and is the registrar's core teardown step, so guarding it would skip the mandatory unregistration in the non-running case (and breaks the RegisterUnregisterTexture unit test, whose engine is never run). Also reflow the FlutterDesktopTextureRegistrarUnregisterExternalTexture call to satisfy clang-format.
1 parent 4cd6db1 commit b390e73

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

flutter/shell/platform/tizen/flutter_tizen.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ void FlutterDesktopTextureRegistrarUnregisterExternalTexture(
330330
int64_t texture_id,
331331
void (*callback)(void* user_data),
332332
void* user_data) {
333-
TextureRegistrarFromHandle(texture_registrar)->UnregisterTexture(
334-
texture_id, callback, user_data);
333+
TextureRegistrarFromHandle(texture_registrar)
334+
->UnregisterTexture(texture_id, callback, user_data);
335335
}
336336

337337
bool FlutterDesktopTextureRegistrarMarkExternalTextureFrameAvailable(

flutter/shell/platform/tizen/flutter_tizen_texture_registrar.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,15 @@ bool FlutterTizenTextureRegistrar::UnregisterTexture(int64_t texture_id,
110110
// glDeleteTextures in the texture's destructor targets the correct
111111
// context (the engine does not guarantee a current context when
112112
// running posted tasks).
113-
if (gl_renderer) {
113+
//
114+
// If the engine has shut down between PostRenderThreadTask() being
115+
// called and this task running, PostRenderThreadTask() runs the task
116+
// inline and the renderer may already be destroyed, so skip
117+
// OnMakeCurrent() to avoid touching a dangling GL context/renderer.
118+
// UnregisterExternalTexture() stays unconditional: it is null-safe at
119+
// the embedder boundary (a torn-down engine handle just yields an
120+
// error) and is the registrar's core teardown step.
121+
if (engine->IsRunning() && gl_renderer) {
114122
gl_renderer->OnMakeCurrent();
115123
}
116124
tex.reset();

0 commit comments

Comments
 (0)