Skip to content

fix(webgl): reset active texture unit on device init for reused contexts#8894

Merged
willeastcott merged 1 commit into
mainfrom
fix/webgl-active-texture-reused-context
Jun 13, 2026
Merged

fix(webgl): reset active texture unit on device init for reused contexts#8894
willeastcott merged 1 commit into
mainfrom
fix/webgl-active-texture-reused-context

Conversation

@willeastcott

@willeastcott willeastcott commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Description

WebGL device init reset the cached active texture unit to 0 but never issued the matching gl.activeTexture(TEXTURE0). On a context reused by a second device — e.g. the Examples hot-reload, which rebuilds the device on the same canvas — the active unit could be left non-zero, so the directional shadow map bound to the wrong unit and shadowed scenes rendered dark. Adds the missing render-state reset.

Fixes #8893

Checklist

  • I have read the contributing guidelines
  • My code follows the project's coding standards
  • This PR focuses on a single change

WebglGraphicsDevice.initializeRenderState reset its cached active texture
unit to 0 but never issued gl.activeTexture(TEXTURE0). On a fresh context
this is harmless (WebGL defaults to unit 0), but when a device is created on
a context previously used by a now-destroyed device - e.g. a second
GraphicsDevice on the same canvas, as the Examples code-editor hot-reload
does - the context can be left on a non-zero active unit. The cache then
disagreed with GL state, so activeTexture(0)'s redundancy check skipped the
call and the first texture bound to unit 0 (such as a directional shadow
map) silently landed on the wrong unit. The sampler2DShadow then read a
non-comparison texture and returned 0, so the whole scene read as shadowed
and rendered dark after hot-reloading an example with a shadow-casting light.

Force the active unit to match the cache during render-state init. This is
a long-standing issue (reproducible back to at least Jan 2025), not a recent
regression.

Fixes #8893

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@willeastcott willeastcott force-pushed the fix/webgl-active-texture-reused-context branch from 4c252ea to bb3e83e Compare June 13, 2026 22:18
@willeastcott willeastcott merged commit d00d406 into main Jun 13, 2026
9 checks passed
@willeastcott willeastcott deleted the fix/webgl-active-texture-reused-context branch June 13, 2026 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

On the examples page, when you click the reload button, the scene light breaks.

1 participant