#12242·pixijs

Concurrent unload and second load return and cache a destroyed texture

Author: mf3493297-pngCreated Sep 27, 2026Updated Sep 27, 2026

Concurrent unload and second load return and cache a destroyed texture

Current behavior

When a texture is still loading, this supported sequence returns an unusable asset to a new consumer:

  1. Start Assets.load(url).
  2. Call Assets.unload(url) before the load completes.
  3. Call Assets.load(url) again while the first load and unload are pending.
  4. Allow the image request to finish.

Both load calls resolve successfully to the same Texture. The pending unload immediately destroys that texture. The second caller therefore receives destroyed === true and source === null. Assets.cache still contains that same destroyed texture.

Expected behavior

A load requested after unload begins should resolve to a fresh usable asset, or the unload/load transition should be serialized or rejected. A destroyed texture must not remain the current cached asset.

Public runnable reproduction

Run:

bash
npm ci
npm start

Open http://127.0.0.1:4173/asset-load-unload-race/?mode=race in Firefox while delaying bunny.png?race by one second. The page prints:

REPRODUCED: {"mode":"race","firstDestroyed":true,"secondDestroyed":true,"secondSourceNull":true,"cachePresent":true,"cacheIsSecond":true,"sameInstance":true}

Verified with the built-in PixiJS PNG texture parser in headed Camoufox.

Neighboring controls

  • ?mode=load-only: returns a live texture and caches that exact instance.
  • ?mode=sequential: waiting for unload before reloading returns a fresh live texture; the old and new instances differ.
  • The race case changes only operation overlap. It has no page errors and uses the same valid PNG.

Root cause

Loader.load() shares the active promise from promiseCache[url]. Loader.unload() also captures that same promise and waits for it. A second load started before completion reuses the same promise:

typescript
if (!this.promiseCache[url])
{
    this.promiseCache[url] = this._getLoadPromiseAndParser(url, asset);
}
assets[asset.src] = await this.promiseCache[url].promise;

After that shared promise resolves, unload deletes the promise entry and destroys the resolved asset:

typescript
const loadedAsset = await loadPromise.promise;
delete this.promiseCache[url];
await loadPromise.parser?.unload?.(loadedAsset, asset, this);

Meanwhile Assets._mapLoadToResolve() caches the value returned to the second caller. The result is a destroyed texture retained as the current cache value.

Impact

This is a deterministic asset lifecycle race in common preload/level-transition workflows. A new scene can successfully await a texture and then receive a destroyed object with no source. Subsequent Assets.get() calls return the same poisoned object, causing missing sprites or rendering failures until another explicit unload/reload repairs the cache.

Environment

  • PixiJS dev commit: 27071aa0096d8749bfdb189857c58178c30cd153
  • npm package: [email protected]
  • Browser: headed Camoufox / Firefox
  • Asset path: built-in PNG texture parser
  • OS: Linux x86_64

Duplicate search

I searched open and closed issues/PRs for concurrent Assets.load/Assets.unload, Loader.promiseCache unload races, and destroyed textures returned by a second load. I found no issue describing this operation-order race. #4653 is an old question about parallel loading, not unload/load lifecycle serialization.

If this fits the bounty program, please consider assigning a bounty label and amount before implementation work begins.