Skip to content

fix(tmx): GPU layer reset crash when currentBatcher lacks deleteTexture2D (#1471)#1474

Merged
obiot merged 1 commit into
masterfrom
fix/1471-tmx-reset-batcher
May 31, 2026
Merged

fix(tmx): GPU layer reset crash when currentBatcher lacks deleteTexture2D (#1471)#1474
obiot merged 1 commit into
masterfrom
fix/1471-tmx-reset-batcher

Conversation

@obiot
Copy link
Copy Markdown
Member

@obiot obiot commented May 31, 2026

Summary

Closes #1471.

OrthogonalTMXLayerGPURenderer.reset() grabbed renderer.currentBatcher and called deleteTexture2D on it — but uploads always flow through the quad batcher (see _drawLayer), and currentBatcher at reset time may be anything. Most notably it's PrimitiveBatcher when the debug plugin's quadtree overlay drew on the previous frame. PrimitiveBatcher 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).

Change

Two adjustments in orthogonal.js::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. The unrelated currentBatcher value at reset time is incidental.
  • 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.

Test plan

  • Added regression spec 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), then gpu.reset() — must not throw and must clear gpu.resources.
  • CHANGELOG ### Fixed entry stamped under 19.7.0 _unreleased_.
  • WebGL2 environment skip applies in CI without GPU — verify locally with a GPU-backed runner if possible.

🤖 Generated with Claude Code

…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>
Copilot AI review requested due to automatic review settings May 31, 2026 07:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@obiot obiot merged commit 2f90e8b into master May 31, 2026
6 of 7 checks passed
@obiot obiot deleted the fix/1471-tmx-reset-batcher branch May 31, 2026 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

QuadTree plugin (16.0): batcher.deleteTexture2D is not a function on stage reset

2 participants