scene: host handles a lost GL context (ground on loss, rebuild on restore) #44

Merged
void merged 2 commits from nibu/context-lost into dev 2026-11-09 22:13:23 +00:00 AGit
Member

Wires the lost-GL-context path (follow-up ratatoskr-onContextLost-host-unwired). Branched from dev, not from the sky-state PR.

  • host.ts passes onContextLost to the scene. On loss it disposes the dead scene (generation bumped so a start still in flight is dropped) and calls the new onInactive; BackgroundScene.tsx removes data-scene so the CSS ground shows.
  • A webglcontextrestored listener on the canvas starts a fresh scene (onActive, login() if a session exists). It is removed on dispose.
  • Fallback on loss is the CSS ground, not TerrainSky2D: a canvas that has held a WebGL context returns no 2D context, so the 2D sky cannot take over on it. A restore that cannot rebuild leaves the ground.
  • Tests (host.test.ts, 7 new): loss disposes and goes inactive without rebuilding; restore rebuilds, activates, logs in; repeated loss/restore disposes each dead scene once; restore while running is ignored; rebuild yielding no scene leaves ground; dispose removes the listener; a start resolving after a loss is dropped.

Run: full vitest 36 files, 479 tests, pass. prettier clean on scene/. eslint clean on the touched files (repo-wide has errors in files not touched). tsc: no errors in host.ts, host.test.ts, BackgroundScene.tsx; the repo-wide run reports 847 errors in other files (matrix-js-sdk typings, Terrain.ts, other tests), which this PR does not touch; I did not diff them against dev's baseline.

Not run in a browser: no real webglcontextlost/restored (e.g. WEBGL_lose_context) against a live canvas. Tests use a fake EventTarget canvas and a mocked startBackgroundScene, so that a real Terrain scene rebuilds cleanly on a restored context (no leaked GL objects, TAA/timer state fresh) is unverified.

Wires the lost-GL-context path (follow-up ratatoskr-onContextLost-host-unwired). Branched from dev, not from the sky-state PR. - `host.ts` passes `onContextLost` to the scene. On loss it disposes the dead scene (generation bumped so a start still in flight is dropped) and calls the new `onInactive`; `BackgroundScene.tsx` removes `data-scene` so the CSS ground shows. - A `webglcontextrestored` listener on the canvas starts a fresh scene (`onActive`, `login()` if a session exists). It is removed on dispose. - Fallback on loss is the CSS ground, not TerrainSky2D: a canvas that has held a WebGL context returns no 2D context, so the 2D sky cannot take over on it. A restore that cannot rebuild leaves the ground. - Tests (host.test.ts, 7 new): loss disposes and goes inactive without rebuilding; restore rebuilds, activates, logs in; repeated loss/restore disposes each dead scene once; restore while running is ignored; rebuild yielding no scene leaves ground; dispose removes the listener; a start resolving after a loss is dropped. Run: full vitest 36 files, 479 tests, pass. prettier clean on scene/. eslint clean on the touched files (repo-wide has errors in files not touched). tsc: no errors in host.ts, host.test.ts, BackgroundScene.tsx; the repo-wide run reports 847 errors in other files (matrix-js-sdk typings, Terrain.ts, other tests), which this PR does not touch; I did not diff them against dev's baseline. Not run in a browser: no real webglcontextlost/restored (e.g. WEBGL_lose_context) against a live canvas. Tests use a fake EventTarget canvas and a mocked startBackgroundScene, so that a real Terrain scene rebuilds cleanly on a restored context (no leaked GL objects, TAA/timer state fresh) is unverified.
scene: host handles a lost GL context (drop to ground, rebuild on restore)
Some checks failed
Build pull request / Build pull request (pull_request) Has been cancelled
3b61f2babf
host.ts passes onContextLost to the scene; on loss it disposes the dead scene
and calls onInactive (BackgroundScene removes data-scene so the CSS ground
shows). A webglcontextrestored listener on the canvas starts a fresh scene;
it is removed on dispose, and a stale start is dropped by generation.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
scene: pin the host's restore-listener removal and stale-loss guard; fix preventDefault comment
Some checks failed
Build pull request / Build pull request (pull_request) Has been cancelled
571a2de3fa
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
void merged commit a129866236 into dev 2026-11-09 22:13:23 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
GameCult/Ratatoskr!44
No description provided.