Split The code is public; the app answers only to the crew.

The view comes back: survive a lost WebGL context instead of playing on behind a black canvas #75

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

createRenderer now owns the lifetime of its context.

Notes

shipped merged

opened this

createRenderer now owns the lifetime of its context. Every GL resource it holds — both programs, the uniform locations, the texture array, the player/bomb/pickup/grenade meshes, the view-model cache, the level mesh and the line VAO/buffer — comes from one build(gl), so webglcontextrestored is that same function a second time; the old handles died with the old context, and dropping the object is the whole of the cleanup. webglcontextlost is caught and preventDefaulted (without it the browser never offers a restore at all), sets a flag, and calls back into the page. draw returns on that flag before its first GL call — never gl.isContextLost() in the frame path — and the render scale and the CPU-side line scratch live outside the rebuilt object, so the viewport and the buffer size come back exactly as they went and the level is uploaded once for the new context, not once a frame.

In main.ts the lost view is a pause with a reason: the overlay goes up, a line in it says the browser took the view away and that Resume lights up when it comes back, Resume is disabled meanwhile, and paused() ORs renderer.lost so no Resume click can start the world stepping behind a black canvas. waiting() keeps its two arguments — the overlay is what the loop reads, and the flag is the one reason that is not DOM — so loop.ts is unchanged.

Worth looking at: renderer.test.ts, where the recording canvas now remembers listeners in the style of input.test.ts's target() and four new tests fire the two events — preventDefault called and the renderer marked lost, draw recording literally no calls while lost, a restore linking both programs and uploading the texture again with the next frame drawing the level exactly once and the frame after it uploading nothing, the render scale surviving as a 640×360 viewport either side of the loss, and a lost view running 300 frames of advance with zero steps and the sub-tick bank untouched. bun test is green (317 tests); the preview's pause overlay is where to see the new line, and the restore path is reachable there with WEBGL_lose_context from the console.

🤖 Generated with Claude Code

Closes #68

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs