diff --git a/packages/assets/test/assets.tests.ts b/packages/assets/test/assets.tests.ts index 31aa7c51b3..1b8327a711 100644 --- a/packages/assets/test/assets.tests.ts +++ b/packages/assets/test/assets.tests.ts @@ -402,4 +402,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(); + }); }); diff --git a/packages/core/src/textures/BaseTexture.ts b/packages/core/src/textures/BaseTexture.ts index b1607b63d3..b40bfee79d 100644 --- a/packages/core/src/textures/BaseTexture.ts +++ b/packages/core/src/textures/BaseTexture.ts @@ -724,7 +724,8 @@ export class BaseTexture 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`); diff --git a/packages/core/src/textures/Texture.ts b/packages/core/src/textures/Texture.ts index 327cc7bd55..f3faf5e353 100644 --- a/packages/core/src/textures/Texture.ts +++ b/packages/core/src/textures/Texture.ts @@ -521,7 +521,8 @@ export class Texture 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`);