Skip to content

Support all AssetPack sound aliases - #285

Merged
zbdd merged 2 commits into
pixijs:mainfrom
StitchAndGlitchStudio:fix-assetpack-sound-aliases
Oct 30, 2026
Merged

zbdd merged 2 commits into
pixijs:mainfrom
StitchAndGlitchStudio:fix-assetpack-sound-aliases

Conversation

@StitchAndGlitchStudio

Copy link
Copy Markdown
Contributor

AssetPack manifests can expose multiple aliases for the same sound, but the sound loader only registers the first entry. This leaves alternate aliases in the PixiJS Assets cache without matching entries in SoundLibrary.

This change:

  • registers every resolved alias against the loaded Sound
  • removes all aliases that reference a Sound when it is removed
  • avoids stopping or destroying the same Sound more than once
  • preserves the basename fallback for direct URL loads and does not remove aliases reassigned to another Sound

Tests cover WebAudio and HTMLAudio loading, playback lookup, unloading, direct URL fallback, reassigned aliases, removeAll, and stopAll.

Fixes #282.

zbdd
zbdd previously requested changes Oct 30, 2026

@zbdd zbdd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for this, the alias handling looks right and the tests look good.

One thing before we merge. close() sets _sounds to null, and Object.values(this._sounds) throws on null, so after sound.close() any of removeAll(), stopAll() or a second close() throws a TypeError. On main all three are fine because for...in over null just does nothing.

Can you guard removeAll() and stopAll() against _sounds being null, and add a test that calls removeAll(), stopAll() and close() after close()? init() again afterwards so the rest of the suite still has a working library.

@zbdd

zbdd commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Pushed a guard for the close() case (c0ab63e) so we can get this in. close() sets _sounds to null and Object.values(null) throws, so removeAll() and stopAll() return early now, which covers a second close() too. Added a test for all three on both backends.

Thanks for the fix.

@zbdd
zbdd dismissed their stale review October 30, 2026 01:33

I made the changes

StitchAndGlitchStudio and others added 2 commits October 30, 2026 09:34
- close() sets _sounds to null and Object.values(null) throws, so removeAll(), stopAll() and a second close() threw a TypeError after close()
- Test calls all three after close() on both backends
@zbdd
zbdd force-pushed the fix-assetpack-sound-aliases branch from c0ab63e to 6cb418f Compare October 30, 2026 01:34
@zbdd
zbdd merged commit 102bf4c into pixijs:main Oct 30, 2026
1 check passed
zbdd added a commit that referenced this pull request Nov 21, 2026
Backport of #285
(cherry picked from commit 102bf4c)

- Cause: v5.x registered an Assets-loaded sound under its first alias
  only, so the other names from `Assets.add(['a', 'b'], url)` or a
  bundle `{ name: ['a', 'b'] }` couldn't be played. A sound under two
  names was destroyed twice by `removeAll()` (#128's crash), and
  unloading a bundle asset with two names threw.
- Fix: register every alias. The first name is unchanged
  (`alias[0]`, or the basename when PixiJS passes no alias), so a URL
  load keeps its old name on every PixiJS 7 version: the basename on
  7.0.x and the full URL where PixiJS passes it as the alias. Main's
  basename rule for URL loads and its `entry !== src` filter aren't
  ported. `unload` removes the alias that still maps to the sound, or
  destroys the sound. `remove()` deletes every key for the sound, and
  `removeAll()`/`stopAll()` act once per sound. The guards after
  `close()` are for parity with main; v5.x didn't throw there.
- Tests: `test/soundAsset.test.ts` ported to PixiJS 7 bundles
  (`{ name, srcs }`), plus v5.x cases for the URL-load name, unloading
  a bundle asset with two names, `removeAll()` with one sound under two
  names, and empty aliases. Both backends.

Co-authored-by: StitchAndGlitchStudio <stitchandglitchstudio@gmail.com>
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.

Sound aliases from AssetPack manifest only use the first alias entry

3 participants