pixijs / pixijs

The HTML5 Creation Engine: Create beautiful digital content with the fastest, most flexible 2D WebGL renderer.
http://pixijs.com
MIT License
43.91k stars 4.78k forks source link

Bug: Assets forces spritesheet to reparse when hitting the cache #9316

Open miltoncandelero opened 1 year ago

miltoncandelero commented 1 year ago

Current Behavior

When Assets hits the cache for a Spritesheet, it triggers the spritesheet to regenerate all the textures.

This could be walked arround by asking if Assets.get(...) already has the spritesheet instead of always calling Assets.load(...) but if your texture is inside a bundle, since there is no way to get the bundle without calling loadBundle the spritesheet always reparse.

Expected Behavior

I think the spritesheet cache should be smart enough to know if it was already parsed or not, or if the parsed textures are still alive or they need reparsing

Steps to Reproduce

Load twice the same spritesheet. The second time you hit the cache but you get warnings about declaring duplicated textures due to the spritesheet parsing again.

See attached repro.

Environment

Possible Solution

No response

Additional Information

No response

alexbown commented 1 year ago

Also getting this issue, in addition to what's mentioned above, the check to show the warning is also incorrect I believe

        cacheKeys.forEach((key) =>
        {
            if (this._cache.has(key) && this._cache.get(key) !== value)
            {
                if (process.env.DEBUG)
                {
                    console.warn('[Cache] already has key:', key);
                }
            }

            this._cache.set(key, cacheableAssets[key]);
        });

Where value is the original asset passed into the function (in this case, the spritesheet) it's comparing each sprite against the sheet to see if they differ, I believe the check should be if (this._cache.has(key) && this._cache.get(key) !== cacheableAssets[key])