Skip to content

Skip drawing while the GL context reports it is lost - #8

Merged
Mistium merged 1 commit into
developfrom
error-report-fixes
Oct 6, 2026
Merged

Mistium merged 1 commit into
developfrom
error-report-fixes

Conversation

@Mistium

@Mistium Mistium commented Oct 6, 2026

Copy link
Copy Markdown
Member

A production error report showed null is not an object (evaluating 'Z.constructor') in twgl's createMIP. The cause: draw() can run after the WebGL context is lost but before the webglcontextlost event has arrived. On a lost context gl.createSampler() returns null, and twgl's isSampler reads .constructor on it.

isContextLost now also asks gl.isContextLost() instead of relying only on the event flag, and draw() uses it.

Tests: the new test/unit/ContextLossTests.js reproduces the crash with a mock context and fails without the fix. Unit tests, npm run build and the integration tests pass.

Not changed here: the nine "Maximum call stack size exceeded" reports in penStamp come from one maze project whose custom blocks recurse thousands of levels deep. MistWarp's recursion limit matches TurboWarp's (about 5,455 levels without warp and 8,964 with warp, against 5,457 and 8,967), so the renderer isn't involved.

No visible surface.

The webglcontextlost event arrives as a separate task, so a frame can still be drawn after the browser has taken the context. If that frame creates the first wrapped texture, twgl's sampler check reads .constructor of the null sampler a lost context returns and throws. draw() now also asks the context itself.
@Mistium
Mistium merged commit 1235f4a into develop Oct 6, 2026
2 checks passed
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.

1 participant