Skip to content

feat(texture): Tear down external textures on the render thread#182

Merged
seungsoo47 merged 3 commits into
flutter-tizen:masterfrom
seungsoo47:webview_lwe_fix
Jul 8, 2026
Merged

feat(texture): Tear down external textures on the render thread#182
seungsoo47 merged 3 commits into
flutter-tizen:masterfrom
seungsoo47:webview_lwe_fix

Conversation

@seungsoo47

Copy link
Copy Markdown
Contributor

UnregisterTexture() previously destroyed the ExternalTexture (running glDeleteTextures) synchronously on the calling platform thread. That could race with an in-flight PopulateGLTexture() on the render thread and free the backing TBM buffer while the GPU still referenced it, causing heap corruption and "tbm_bo_free ... lock_cnt" crashes on the SW backend.

  • Add a completion-callback parameter to UnregisterTexture, plumbed through FlutterDesktopTextureRegistrarUnregisterExternalTexture, so callers learn when teardown has actually completed.
  • Add FlutterTizenEngine::PostRenderThreadTask(), a thin wrapper over the embedder API's PostRenderThreadTask.
  • UnregisterTexture now removes the texture from the map (blocking new lookups), then posts its destruction to the render thread. The engine runs that task only after any in-flight frame callback has completed, so it no longer races; glDeleteTextures runs on the thread that owns the GL context, and the completion callback fires only once teardown is done.

UnregisterTexture() previously destroyed the ExternalTexture (running
glDeleteTextures) synchronously on the calling platform thread. That could
race with an in-flight PopulateGLTexture() on the render thread and free the
backing TBM buffer while the GPU still referenced it, causing heap corruption
and "tbm_bo_free ... lock_cnt" crashes on the SW backend.

- Add a completion-callback parameter to UnregisterTexture, plumbed through
  FlutterDesktopTextureRegistrarUnregisterExternalTexture, so callers learn
  when teardown has actually completed.
- Add FlutterTizenEngine::PostRenderThreadTask(), a thin wrapper over the
  embedder API's PostRenderThreadTask.
- UnregisterTexture now removes the texture from the map (blocking new
  lookups), then posts its destruction to the render thread. The engine runs
  that task only after any in-flight frame callback has completed, so it no
  longer races; glDeleteTextures runs on the thread that owns the GL context,
  and the completion callback fires only once teardown is done.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the texture unregistration process to defer the destruction of external textures and their GPU resources to the render thread using PostRenderThreadTask. Feedback indicates that if the engine is not running and the task is executed inline, calling OnMakeCurrent and UnregisterExternalTexture is unsafe due to a potentially destroyed GL context or null engine handle. A guard using engine->IsRunning() is suggested to prevent crashes.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread flutter/shell/platform/tizen/flutter_tizen_texture_registrar.cc
@JSUYA
JSUYA requested a review from xiaowei-guan July 7, 2026 08:51
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.
Comment thread flutter/shell/platform/tizen/flutter_tizen_engine.cc Outdated
xiaowei-guan
xiaowei-guan previously approved these changes Jul 8, 2026
Comment thread flutter/shell/platform/tizen/flutter_tizen_engine.h
@xiaowei-guan
xiaowei-guan self-requested a review July 8, 2026 05:23
@xiaowei-guan
xiaowei-guan dismissed their stale review July 8, 2026 05:24

wait update code

PostRenderThreadTask() ignored the embedder API's return value. If posting
failed (e.g. engine shutdown began concurrently with the IsRunning() check),
the heap-allocated task was never scheduled and never freed, and worse, the
texture teardown/completion callback it carried would never run.

Run the task inline when posting fails, mirroring the existing !engine_
fallback, instead of widening the API to return a bool that the sole caller
couldn't act on any differently.
@seungsoo47
seungsoo47 merged commit ee9f5f2 into flutter-tizen:master Jul 8, 2026
10 checks passed
seungsoo47 added a commit to seungsoo47/plugins that referenced this pull request Jul 15, 2026
…rash

Rework WebView::Dispose() to tear resources down safely:

- Detach all engine callbacks (including the missing
  "policy,response,decide") and defer evas_object_del() until the
  embedder's UnregisterTexture completion callback, so the engine-owned
  TBM surfaces are not freed while a raster-thread frame is still reading
  them (flutter-tizen/embedder#182).
- Add is_alive_/is_disposing_ guards so async callbacks arriving after
  disposal no longer touch the destroyed WebView.
- On the Tizen 10.0 TV emulator (TV_PROFILE + x86_64), hide the stopped
  view instead of deleting it to avoid a SIGSEGV in chromium-efl's
  ~SelectionControllerEfl(); revert once the engine fix ships.

Verified on the TV 10.0 emulator: example integration tests previously
crashed on WebView disposal and now pass 19/19.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants