Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/cache warning fix #8949

Merged
merged 5 commits into from Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/assets/test/assets.tests.ts
Expand Up @@ -402,4 +402,20 @@ describe('Assets', () =>

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

it('should load not show a cache warning if the same asset is loaded twice', async () =>
bigtimebuddy marked this conversation as resolved.
Show resolved Hide resolved
{
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 @@ -724,7 +724,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 @@ -521,7 +521,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