Skip to content

Commit dcdc1a5

Browse files
committed
fix(texture): guard render-thread teardown against engine shutdown
The render-thread teardown task posted by UnregisterTexture() captured a raw engine pointer and only checked that the engine existed at post time. If the engine shuts down before the task runs (PostRenderThreadTask then runs it inline), calling gl_renderer->OnMakeCurrent() and engine->UnregisterExternalTexture() touches an already-destroyed GL context and a null engine handle. Guard both calls with engine->IsRunning() inside the task; tex.reset() and the completion callback still run unconditionally so the texture is released and callers (e.g. webview_flutter_lwe) always get their 'safe to free' signal. Also reflow the FlutterDesktopTextureRegistrarUnregisterExternalTexture call to satisfy clang-format.
1 parent 4cd6db1 commit dcdc1a5

2 files changed

Lines changed: 13 additions & 4 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: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,20 @@ 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+
// The engine may have shut down between PostRenderThreadTask() being
115+
// called and this task running, in which case the GL context is
116+
// already gone and the engine handle is null; skip the GL/engine
117+
// calls in that case but still release the texture and fire the
118+
// completion callback.
119+
const bool is_running = engine->IsRunning();
120+
if (is_running && gl_renderer) {
114121
gl_renderer->OnMakeCurrent();
115122
}
116123
tex.reset();
117-
engine->UnregisterExternalTexture(texture_id);
124+
if (is_running) {
125+
engine->UnregisterExternalTexture(texture_id);
126+
}
118127
if (callback) {
119128
callback(user_data);
120129
}

0 commit comments

Comments
 (0)