fix(webgl): reset active texture unit on device init for reused contexts#8894
Merged
Merged
Conversation
24d5651 to
a4d5dd6
Compare
a4d5dd6 to
4c252ea
Compare
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>
4c252ea to
bb3e83e
Compare
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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