fix(examples): replace textureOptions wholesale instead of mutating frozen default#93
Merged
Merged
Conversation
…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>
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.
Problem
The default examples page (
?test=test) throws repeatedly on load:Nodes created without
textureOptionsresolve to a single sharedObject.freeze({})default (EMPTY_TEXTURE_OPTIONSinsrc/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.ts—node.textureOptions.flipX = flipXon every animation frameexamples/tests/texture-cleanup-critical.ts—screen.textureOptions.preload = trueon every interval tick (same latent bug, different test page)Fix
Assign a new options object through the
textureOptionssetter instead of mutating:this.node.textureOptions = { flipX }once per direction change. Safe because thetexturesetter resetstextureCoordson every frame swap and coords are recomputed from the current options, so the flip applies to each new frame.screen.textureOptions = { preload: true }once before the interval;preloadis read on each texture load.Verification
Loaded
http://localhost:5173/?test=testwith 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