Skip to content

fix(examples): replace textureOptions wholesale instead of mutating frozen default#93

Merged
chiefcll merged 1 commit into
mainfrom
fix/examples-frozen-texture-options
Jun 10, 2026
Merged

fix(examples): replace textureOptions wholesale instead of mutating frozen default#93
chiefcll merged 1 commit into
mainfrom
fix/examples-frozen-texture-options

Conversation

@chiefcll

Copy link
Copy Markdown
Contributor

Problem

The default examples page (?test=test) throws repeatedly on load:

TypeError: Cannot add property flipX, object is not extensible
    at nextFrame (examples/common/Character.ts:60)

Nodes created without textureOptions resolve to a single shared Object.freeze({}) default (EMPTY_TEXTURE_OPTIONS in src/core/Stage.ts), whose documented contract is "only ever read or replaced wholesale (never mutated in place)". Two examples violated that contract by mutating the object in place:

  • examples/common/Character.tsnode.textureOptions.flipX = flipX on every animation frame
  • examples/tests/texture-cleanup-critical.tsscreen.textureOptions.preload = true on every interval tick (same latent bug, different test page)

Fix

Assign a new options object through the textureOptions setter instead of mutating:

  • Character: this.node.textureOptions = { flipX } once per direction change. Safe because the texture setter resets textureCoords on every frame swap and coords are recomputed from the current options, so the flip applies to each new frame.
  • texture-cleanup-critical: screen.textureOptions = { preload: true } once before the interval; preload is read on each texture load.

Verification

Loaded http://localhost:5173/?test=test with the console open: zero errors after the fix (confirmed against a console marker to rule out stale log entries), and screenshots ~30s apart show the Rocko sprites still animating (walk frames advancing). Prettier + ESLint pass.

🤖 Generated with Claude Code

…rozen default

Nodes created without textureOptions share a frozen EMPTY_TEXTURE_OPTIONS
object (Stage.ts), so in-place mutation throws "Cannot add property,
object is not extensible". Assign a new options object through the
setter instead, per the documented contract.

Fixes the TypeError spam on ?test=test (Character.ts) and the same
latent pattern in texture-cleanup-critical.ts.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@chiefcll chiefcll merged commit c811732 into main Jun 10, 2026
1 check passed
@chiefcll chiefcll deleted the fix/examples-frozen-texture-options branch June 10, 2026 12:58
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.

1 participant