fix(tmx): GPU layer reset crash when currentBatcher lacks deleteTexture2D (#1471)#1474
Merged
Conversation
…re2D (#1471) `OrthogonalTMXLayerGPURenderer.reset()` grabbed `renderer.currentBatcher` and called `deleteTexture2D` on it — but uploads always flow through the "quad" batcher (see `_drawLayer`), and the currently-active batcher at reset time may be anything: most notably `PrimitiveBatcher` when the debug plugin's quadtree overlay drew on the previous frame. Primitive batcher has no `deleteTexture2D`, so every stage change threw `TypeError: batcher.deleteTexture2D is not a function` and the resource map was never cleared (so the next level would accumulate stale entries even if the throw were caught). Two changes in `reset()`: - Pin the batcher lookup to the same batcher we upload to: `renderer.batchers.get("quad")` instead of `currentBatcher`. This is the correct architectural choice — the texture was bound there, the deletion path must walk the same `boundTextures` table. - Guard the call with `typeof batcher?.deleteTexture2D === "function"` so a user-supplied `settings.batcher` custom class that doesn't extend `MaterialBatcher` falls through to the manual `cache.delete()` / `cache.freeTextureUnit()` path instead of crashing. Regression spec in `tmxlayer-shader.spec.js`: upload a layer through the quad batcher, switch to the primitive batcher (mimicking the debug-plugin overlay), then `gpu.reset()` — must not throw and must clear `gpu.resources`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Closes #1471.
OrthogonalTMXLayerGPURenderer.reset()grabbedrenderer.currentBatcherand calleddeleteTexture2Don it — but uploads always flow through the quad batcher (see_drawLayer), andcurrentBatcherat reset time may be anything. Most notably it'sPrimitiveBatcherwhen the debug plugin's quadtree overlay drew on the previous frame.PrimitiveBatcherhas nodeleteTexture2D, so every stage change threwTypeError: batcher.deleteTexture2D is not a functionand the resource map was never cleared (so the next level would accumulate stale entries even if the throw were caught).Change
Two adjustments in
orthogonal.js::reset():renderer.batchers.get("quad")instead ofcurrentBatcher. This is the correct architectural choice — the texture was bound there, the deletion path must walk the sameboundTexturestable. The unrelatedcurrentBatchervalue at reset time is incidental.typeof batcher?.deleteTexture2D === "function"so a user-suppliedsettings.batchercustom class that doesn't extendMaterialBatcherfalls through to the manualcache.delete()/cache.freeTextureUnit()path instead of crashing.Test plan
tmxlayer-shader.spec.js::"survives reset() even when currentBatcher is not a MaterialBatcher": upload a layer through the quad batcher, switch to the primitive batcher (mimicking the debug-plugin overlay), thengpu.reset()— must not throw and must cleargpu.resources.### Fixedentry stamped under 19.7.0_unreleased_.🤖 Generated with Claude Code