You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TextureCache.get(image, { framewidth, frameheight }) in packages/melonjs/src/video/texture/cache.js:166 documents itself as picking the atlas under image whose dimensions match the requested frame size, useful when an image has multiple atlases registered (e.g. a cropped variant alongside the full-image default). In practice the refinement loop is a no-op against every atlas format the engine produces — it has been dormant for as long as the parser has been unified.
Surfaced while writing adversarial tests for #1448; not a live bug today, but worth pinning before it bites.
this.atlases is populated by parseTexturePacker(atlas, this) for every format — TexturePacker, Aseprite, ShoeBox, AND the "melonJS" format produced by createAtlas() (the pattern path) all route through the same parser.
parseTexturePacker (packages/melonjs/src/video/texture/parser/texturepacker.js:41) builds a frame-keyed dict: atlas[frame.filename] = { width: s.w, height: s.h, ... }. So _atlas is { default: { width: 64, height: 64, ... } }, not { width: 64, height: 64 }.
_atlas.width is always undefined. undefined === framewidth is always false. The loop never updates entry. The function always returns cache.get(image)[0].
Why nothing observably breaks today
Single-atlas-per-image is the common case (sprites, sprite sheets, tilesets). Refining "the only one" → "still the only one" is no-op anyway.
The existing test texture.spec.js > should retrieve specific atlas by frame dimensions only asserts toBeDefined() — which holds even when the refinement no-ops, so the test passes against the broken behavior.
A. Fix the comparison to use the right path. Compare _atlas[Object.keys(_atlas)[0]].width / height or, more semantically, peek at the underlying meta.size.w / .h if accessible. Real behavioral change — could surface latent bugs in any caller that's accidentally been relying on always getting cache.get(image)[0].
B. Expose top-level .width / .height on the parsed atlas dict. Tweak parseTexturePacker (and the createAtlas "melonJS"-format equivalent) to also set top-level .width and .height on the dict so the existing comparison works as intended.
C. Drop the framewidth/frameheight argument entirely. If no caller in the engine actually relies on it (grep suggests none do), removing the dead branch keeps the API smaller and prevents future confusion. The existing test would need updating.
Recommendation
Defer to the #1410 (TextureCache + Batcher renderer-agnostic refactor) reviewer / author — they'll touch this whole API surface anyway, and the right answer (which of A/B/C) depends on whether the framewidth refinement is intentional API or a vestige.
Summary
TextureCache.get(image, { framewidth, frameheight })inpackages/melonjs/src/video/texture/cache.js:166documents itself as picking the atlas underimagewhose dimensions match the requested frame size, useful when an image has multiple atlases registered (e.g. a cropped variant alongside the full-image default). In practice the refinement loop is a no-op against every atlas format the engine produces — it has been dormant for as long as the parser has been unified.Surfaced while writing adversarial tests for #1448; not a live bug today, but worth pinning before it bites.
How it's silent
getAtlas()returnsthis.atlases.get(this.activeAtlas).this.atlasesis populated byparseTexturePacker(atlas, this)for every format — TexturePacker, Aseprite, ShoeBox, AND the"melonJS"format produced bycreateAtlas()(the pattern path) all route through the same parser.parseTexturePacker(packages/melonjs/src/video/texture/parser/texturepacker.js:41) builds a frame-keyed dict:atlas[frame.filename] = { width: s.w, height: s.h, ... }. So_atlasis{ default: { width: 64, height: 64, ... } }, not{ width: 64, height: 64 }._atlas.widthis alwaysundefined.undefined === framewidthis alwaysfalse. The loop never updatesentry. The function always returnscache.get(image)[0].Why nothing observably breaks today
texture.spec.js > should retrieve specific atlas by frame dimensionsonly assertstoBeDefined()— which holds even when the refinement no-ops, so the test passes against the broken behavior.Options
A. Fix the comparison to use the right path. Compare
_atlas[Object.keys(_atlas)[0]].width / heightor, more semantically, peek at the underlyingmeta.size.w / .hif accessible. Real behavioral change — could surface latent bugs in any caller that's accidentally been relying on always gettingcache.get(image)[0].B. Expose top-level
.width/.heighton the parsed atlas dict. TweakparseTexturePacker(and the createAtlas "melonJS"-format equivalent) to also set top-level.widthand.heighton the dict so the existing comparison works as intended.C. Drop the framewidth/frameheight argument entirely. If no caller in the engine actually relies on it (grep suggests none do), removing the dead branch keeps the API smaller and prevents future confusion. The existing test would need updating.
Recommendation
Defer to the #1410 (TextureCache + Batcher renderer-agnostic refactor) reviewer / author — they'll touch this whole API surface anyway, and the right answer (which of A/B/C) depends on whether the framewidth refinement is intentional API or a vestige.
Cross-refs