mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-15 13:58:20 +00:00
Browsers cap concurrent WebGL contexts (~16) and silently drop the oldest. HyperShader had no `webglcontextlost` listener, so a dropped context was permanent and surfaced as a transition that stopped rendering with no diagnostic; the context itself was only reclaimed when the canvas became collectable. Generalise the pattern already used by the runtime colour grader: - `manageContextLoss()` in webgl.ts cancels the default (unrecoverable) loss action, reports loss/restore, and returns a teardown that calls `WEBGL_lose_context.loseContext()` explicitly. - While the context is lost, HyperShader routes active transitions through the existing DOM crossfade and skips all texture uploads, so the composition keeps playing and no GL call touches a dead context. - On restore, programs, the quad buffer, the blend program and both interpolation render targets are rebuilt as a unit and the cached snapshot textures are re-uploaded from their blobs. - The shared vertex shader is no longer cached in a module-level singleton: it outlived its context, so every program linked after a restore would have linked against a dead shader. Verified in headless Chrome with real WebGL (SwiftShader): a shader transition under a forced `loseContext()` drops to 0 GL draws and crossfades in the DOM, then resumes real rendering after `restoreContext()`.