v19.6.0
What's New in melonJS 19.6.0
WebGL context-loss hardening release. Fixes a Windows + Chrome crash where a GPU switch lost the WebGL context and a partial GLShader.destroy() left the next frame's setUniform("uTime", …) reading from null uniforms. Beyond the crash, the renderer now transparently recovers the rest of the pipeline (vertex buffer, default GL state, batchers, texture cache) across a webglcontextlost → webglcontextrestored cycle, and shaders replay their cached uniforms on restore — so the game keeps drawing across a GPU switch without any intervention from user code.
New Features
- Transparent WebGL context recovery, pipeline-wide — the renderer re-creates its vertex buffer, re-applies default GL state, re-initialises every batcher, drops stale texture-unit assignments, and emits
ONCONTEXT_RESTOREDsoGLShader/ShaderEffectinstances recompile + replay their cached uniforms. NVIDIA Optimus GPU switches, browser tab eviction recovery, andWEBGL_lose_contextteardowns no longer require user code to re-apply uniforms, re-upload textures, or recreate shaders. GLShader.destroyed/GLShader.suspended/ShaderEffect.destroyed— public read-only diagnostic flags.destroyedis the stable "explicitly released" signal (distinct fromShaderEffect.enabled, which auto-toggles across the cycle);suspendedis true only between lost and restored.
Changed
- Platformer example coins migrated to per-instance
ShineEffect, matching the pattern of every other 19.5+ shader-using example.GAME_UPDATEsubscription tied toonActivateEvent/onDeactivateEventso pool-recycled coins re-bind on respawn instead of leaking a dead handler per pickup.
Bug Fixes
- Stale shader references no longer crash —
GLShader.destroy()is atomic + idempotent and wrapsgl.deleteProgramin a try / catch, so a throw on a dead ANGLE / D3D11 context (the 19.5.0 Windows + ChromeTypeError: Cannot read properties of null (reading 'uTime')crash) can't leave a half-destroyed shader. PublicsetUniform/bind/getAttribLocationpaths also no-op on destroyed shaders instead of throwing. ShaderEffect.destroy()setsenabled = falseBEFORE the inner destroy — even if the inner destroy throws outward, the effect's public methods are already in the safe no-op state via theenabledgate.GLShader._uniformCachesnapshots arrays / typed arrays viacaptureValueon write, so caller mutation aftersetUniformcan't silently rewrite what replays on context restore.ShaderEffect.enabledauto-toggle preserves user-set state across a context cycle — an effect the user explicitly disabled stays disabled after restore.
Performance
GLShader.setUniformzero-allocation hot path — the replay cache reuses the existing slot's array (viacaptureValue) when the value's length matches. Steady-state writes for the same uniform name (light positions, animation uniforms, per-frameuTime) no longer allocate a fresh array on every call.
Install
npm install melonjs@19.6.0