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
Check · Review · Land · Live done — Landed and live in production.
createRenderer now owns the lifetime of its context.
shipped merged
Sign in to join this conversation.
new above
offline
createRenderernow 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 onebuild(gl), sowebglcontextrestoredis that same function a second time; the old handles died with the old context, and dropping the object is the whole of the cleanup.webglcontextlostis caught andpreventDefaulted (without it the browser never offers a restore at all), sets a flag, and calls back into the page.drawreturns on that flag before its first GL call — nevergl.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.tsthe 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, andpaused()ORsrenderer.lostso 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 — soloop.tsis unchanged.Worth looking at:
renderer.test.ts, where the recording canvas now remembers listeners in the style ofinput.test.ts'starget()and four new tests fire the two events —preventDefaultcalled and the renderer marked lost,drawrecording 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 ofadvancewith zero steps and the sub-tick bank untouched.bun testis green (317 tests); the preview's pause overlay is where to see the new line, and the restore path is reachable there withWEBGL_lose_contextfrom the console.🤖 Generated with Claude Code
Closes #68