WebGL context-loss / context-restoration concern extracted from
scene/scene-manager.ts.
Owns the full lifecycle of a graceful WebGL recovery:
Loss: a webglcontextlost event fires when the GPU driver
crashes, the system hibernates, the browser hits its WebGL
context limit, or GPU memory runs out. We preventDefault (the
spec requires this for the browser to even attempt restoration),
flip an isContextLost flag, and surface an error toast.
Restoration: when webglcontextrestored fires, we walk a
deterministic rebuild order — renderer.resetState →
postProcessing.rebuildAfterContextRestore →
materialManager.rebuildAfterContextRestore →
mark-scene-resources-dirty → updateRendererSize. Then we
dispatch webgl-context-restored so subscribers (SceneLoader,
NodeFactory, picking) can re-register their per-context state,
and change to trigger a render.
The class is a THREE.EventDispatcher so it stays compatible with
the existing SceneManager pattern of dispatching webgl-context-restored
on its own surface — the SceneManager forwards the event after
receiving it from the recovery instance.
Behavior is identical to the inline original: same guard messages,
same rebuild order, same dispatch-events-after-restore sequence.
WebGL context-loss / context-restoration concern extracted from
scene/scene-manager.ts.Owns the full lifecycle of a graceful WebGL recovery:
Loss: a
webglcontextlostevent fires when the GPU driver crashes, the system hibernates, the browser hits its WebGL context limit, or GPU memory runs out. WepreventDefault(the spec requires this for the browser to even attempt restoration), flip anisContextLostflag, and surface an error toast.Restoration: when
webglcontextrestoredfires, we walk a deterministic rebuild order — renderer.resetState → postProcessing.rebuildAfterContextRestore → materialManager.rebuildAfterContextRestore → mark-scene-resources-dirty → updateRendererSize. Then we dispatchwebgl-context-restoredso subscribers (SceneLoader, NodeFactory, picking) can re-register their per-context state, andchangeto trigger a render.The class is a
THREE.EventDispatcherso it stays compatible with the existing SceneManager pattern of dispatchingwebgl-context-restoredon its own surface — the SceneManager forwards the event after receiving it from the recovery instance.Behavior is identical to the inline original: same guard messages, same rebuild order, same dispatch-events-after-restore sequence.