fix(webgl): release the GL context on dispose - #6069
Open
openwong2kim wants to merge 1 commit into
Open
Conversation
WebglAddon.dispose() detached the canvas but never freed the underlying WebGL2 context, so it lingered until garbage collection. Browsers cap the number of live WebGL contexts per document (Chromium ~16); in apps that create and dispose many terminals these orphaned contexts pile up and the browser force-evicts the oldest LIVE context, blanking an active terminal. Explicitly call WEBGL_lose_context.loseContext() in the renderer teardown so the context is released immediately and the live count stays bounded.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6068
What
Explicitly lose the WebGL2 context when the WebGL renderer is disposed, by
calling
WEBGL_lose_context.loseContext()in the renderer's teardown:Why
WebglAddon.dispose()detached the canvas but never released the underlyingWebGL2 context. It lingered until garbage collection, so every disposed addon
left a zombie context behind. Browsers cap the number of live WebGL contexts
per document (Chromium ~16, driver/build dependent); once an app creates and
disposes enough terminals to cross the cap, the browser force-evicts the
oldest context — which can belong to a terminal that is still on screen — and
that live terminal goes blank. See #6068 for a repro and full
analysis.
loseContext()is the standard, documented way to release a contextdeterministically.
getExtension('WEBGL_lose_context')is optional-chained soa browser that does not expose the extension simply degrades to the previous
(leak-on-GC) behavior instead of throwing.
Tests
Added
addons/addon-webgl/test/WebglContextRelease.test.ts, an integration testthat spies on
WEBGL_lose_context.loseContextand assertsdispose()invokesit exactly once. The cap-eviction itself is GPU/driver dependent and does not
reproduce under headless SwiftShader, so the test verifies the mechanism
directly rather than trying to force an eviction. Verified it fails without this
change (loseContext called 0 times) and passes with it.
npm run tsc— cleaneslinton the changed files — cleanfailures under headless SwiftShader are unaffected by this change (they fail
identically on
master).