Repository navigation
Survive WebGL context loss and sparse draw lists - #3
Merged
Merged
Conversation
- The renderer now listens for webglcontextlost and webglcontextrestored on its canvas. Losing the context calls preventDefault so the browser can give it back, sets isContextLost, skips draw() until then, and emits ContextLost. Restoring rebuilds the shader cache, geometry, and draw region state, asks every skin to drop the textures that died with the old context, and emits ContextRestored. SVG and text bubble skins rebuild from their source on the next draw; the pen layer recreates its buffers and framebuffer; bitmap skins stay empty until they are set again. - pick() ignores holes and destroyed ids in the draw list. With real layer indexes enabled the list is sparse, and clicking the stage threw on the first hole. - A shader compile failure now includes the start of the source that was compiled, so a syntax error on line 1 shows what the bundler handed over instead of the shader. - The resource disposal test file lints again, so npm test no longer fails at the lint step. Co-Authored-By: Claude Fable 5.1 <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.
Two crash paths in the renderer and one diagnostic.
WebGL context loss. Nothing listened for
webglcontextlost, so when the browser took the context away (GPU reset, too many WebGL tabs, a backgrounded mobile tab) the nextdraw()failed inside_buildShaderwith an unhelpful compile error, and because nothing calledpreventDefaultthe browser never tried to restore the context. The renderer now:preventDefaulton loss, setsisContextLost, skipsdraw()while lost, and emitsContextLost;ContextRestored.Each skin gets an
onContextRestoredhook. SVG skins rebuild their MIPs from the still-loaded image on the next draw, text bubbles re-render from their text, the pen layer recreates its shaders, buffers, and framebuffer (its contents are gone, as they would be in any renderer), and bitmap skins stay empty until the VM sets them again. The VM and GUI can listen for the two events to reload costumes or tell the user; this PR keeps the renderer usable and quiet instead of throwing every frame.Sparse draw list. With the experimental real layer indexes setting enabled,
setDrawableOrderleaves holes in_drawList, and shifting entries turns holes into explicitundefined._drawTheseand_candidatesTouchingalready skip those, butpick()did not, so clicking the stage threw on the first hole. It now skips holes and destroyed ids.Shader diagnostics. Production has reported
ERROR: 0:1: 'vertex' : syntax error, which cannot come fromsprite.vertitself: line 1 of every compiled shader is a#define. The compile failure now includes the first 80 characters of the vertex and fragment source that were actually compiled, so the next report shows what the bundler handed over.Also fixes the lint errors in
test/unit/ResourceDisposalTests.jssonpm testno longer fails at the lint step.Tests:
eslint .clean,tap test/unitpasses (newContextLossTests.jscovers the lost and restored paths and the sparse pick), andnpm run build && tap test/integrationpasses (pick, scratch, skin size).No visible surface.