Skip to content

Commit

Permalink
Suppress cache warnings when attempting to load the same asset (#8949)
Browse files Browse the repository at this point in the history
  • Loading branch information
GoodBoyDigital authored and bigtimebuddy committed Dec 12, 2022
1 parent 66c6847 commit b9fbbfc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
16 changes: 16 additions & 0 deletions packages/assets/test/assets.tests.ts
Expand Up @@ -404,4 +404,20 @@ describe('Assets', () =>

expect(font).toBeInstanceOf(FontFace);
});

it('should not show a cache warning if the same asset is loaded twice', async () =>
{
await Assets.init({
basePath,
});

const spy = jest.spyOn(console, 'warn');

const bunnyPromise = Assets.load('textures/bunny.png');
const bunnyPromise2 = Assets.load('textures/bunny.png');

await Promise.all([bunnyPromise, bunnyPromise2]);

expect(spy).not.toHaveBeenCalled();
});
});
3 changes: 2 additions & 1 deletion packages/core/src/textures/BaseTexture.ts
Expand Up @@ -669,7 +669,8 @@ export class BaseTexture<R extends Resource = Resource, RO = IAutoDetectOptions>
baseTexture.textureCacheIds.push(id);
}

if (BaseTextureCache[id])
// only throw a warning if there is a different base texture mapped to this id.
if (BaseTextureCache[id] && BaseTextureCache[id] !== baseTexture)
{
// eslint-disable-next-line no-console
console.warn(`BaseTexture added to the cache with an id [${id}] that already had an entry`);
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/textures/Texture.ts
Expand Up @@ -520,7 +520,8 @@ export class Texture<R extends Resource = Resource> extends EventEmitter
texture.textureCacheIds.push(id);
}

if (TextureCache[id])
// only throw a warning if there is a different texture mapped to this id.
if (TextureCache[id] && TextureCache[id] !== texture)
{
// eslint-disable-next-line no-console
console.warn(`Texture added to the cache with an id [${id}] that already had an entry`);
Expand Down

0 comments on commit b9fbbfc

Please sign in to comment.