fix(webgl): release throwaway context in premultiply-alpha probe#114
Merged
Conversation
`detectPremultiplyAlphaHonored` creates a temporary WebGL context to test
whether `createImageBitmap(..., { premultiplyAlpha: 'premultiply' })` is
honored, but it only deleted the texture/framebuffer — the context itself was
left dangling until GC.
This probe runs in a microtask *after* the main render context is created, so a
leaked context here is the newest one on the page. On embedded TV browsers
(Apollo/Sunrise, Chrome 38+) the live-context budget is tiny; the lingering
probe pushes the page over the limit and the browser evicts the *oldest*
context — the live render context — after which every `createTexture()` returns
null and the engine spams "Could not create WebGL Texture" each frame.
Release the probe context immediately via `WEBGL_lose_context` on every exit
path instead of waiting for GC. The lose event fires only on the throwaway
canvas, so it does not trip the main renderer's `webglcontextlost` handler.
Only active when `premultiplyAlphaHonored: 'auto'` is set (default is `true`,
no probe).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
What
detectPremultiplyAlphaHonored(src/core/lib/validateImageBitmap.ts) creates a temporary WebGL context to test whethercreateImageBitmap(..., { premultiplyAlpha: 'premultiply' })is honored by the browser. It deleted the texture and framebuffer it used, but left the WebGL context itself dangling until GC.This change releases that context immediately via
WEBGL_lose_context.loseContext()on the exit path.Why
Reported on Apollo/Sunrise TV boxes (Chrome 38+):
Embedded TV SoCs cap the number of live WebGL contexts very low. This probe runs in a microtask after the main render context is created, so a leaked probe context is the newest on the page. Holding that extra slot can push the page over the device's context budget, and the browser evicts the oldest context — the live render context. Once that happens,
gl.createTexture()returnsnulland the engine spamsCould not create WebGL TextureeveryrequestAnimationFrame.Don't wait for GC to reclaim the canvas — drop the context the moment the probe is done.
Notes for reviewers
loseContextevent fires only on the throwaway canvas, so it does not trip the main renderer'swebglcontextlosthandler in WebGlRenderer.ts.premultiplyAlphaHonored: 'auto'. The default istrue(no probe), so default configs are unaffected.@solidtv/solidlayer (getWebglSupportedVersions, which re-created a context on every non-default call); that fix ships as a separate PR in that repo.Tests
getExtensionto the mock GL in validateImageBitmap.test.ts and a test assertingloseContext()is called exactly once.pnpm vitest run src/core/lib/validateImageBitmap.test.ts→ 7/7 pass.tsc --buildclean; prettier + eslint clean (0 errors).🤖 Generated with Claude Code