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

Fix TextureLoaderStore not always appending extensions to lookups #5287

Merged
merged 3 commits into from
Jul 3, 2022

Conversation

frenzibyte
Copy link
Member

@frenzibyte frenzibyte commented Jul 3, 2022

Tournament texture storage uses a StorageBackedResourceStore, which is not of type ResourceStore, therefore TextureLoaderStore can't append the image extensions and fail lookups:

public TextureLoaderStore(IResourceStore<byte[]> store)
{
this.store = store;
(store as ResourceStore<byte[]>)?.AddExtension(@"png");
(store as ResourceStore<byte[]>)?.AddExtension(@"jpg");
}

This is a regression from #5240, since prior to that PR, TextureStore appends extensions as well (this is also the reason why previously texture store sometimes looks up textures with double extensions, i.e. texture.jpg.png).

Instead, I've changed TextureLoaderStore to explicitly construct a resource store and add the given store along with the right extensions there, rather than safely cast and silently fail.

Note that SampleStore and TrackStore suffer from the same issue, which would fail similarly if constructed with a non-ResourceStore<T> store (e.g. StorageBackedResourceStore).

@peppy
Copy link
Member

peppy commented Jul 3, 2022

Tests need attention here.

`getFunc` calls `baseStore`, which has nothing to do with textures,
therefore it has to explicitly specifiy the extension.

Alternative would be carrying the extension provided from `name` in the
`getWithBlocking` method, but I'm not sure that's necessary.
@pull-request-size pull-request-size bot added size/S and removed size/XS labels Jul 3, 2022
@frenzibyte
Copy link
Member Author

frenzibyte commented Jul 3, 2022

Turns out in master, TextureLoaderStore populates the texture extensions to game.Resources, due to...

addFont(localFonts, Resources, @"Fonts/Roboto/Roboto-Regular");

private void addFont(FontStore target, ResourceStore<byte[]> store, string assetName = null)
=> target.AddTextureSource(new RawCachingGlyphStore(store, assetName, Host.CreateTextureLoaderStore(store)));

(notice Resources passed to addFont, which creates a texture loader store of it)

That is also the reason why we see lookups like file.mp3.jpg all over the place game-side.

This is relevant in the test failure because the test was never supposed to work without specifying the extension, but it was actually working because of the png/jpg extensions being added to game.Resources:

BlockingOnlineStore = new BlockingResourceStore(new NamespacedResourceStore<byte[]>(game.Resources, "Textures"));
NormalStore = new TextureStore(host.CreateTextureLoaderStore(BlockingOnlineStore));
LargeStore = new LargeTextureStore(host.CreateTextureLoaderStore(BlockingOnlineStore));

(notice game.Resources there in the store flow)

@frenzibyte
Copy link
Member Author

I'll run tests game-side and confirm this doesn't regress skins and storyboards just to be sure.

@frenzibyte
Copy link
Member Author

frenzibyte commented Jul 3, 2022

Can't seem to find any issues so far. This is ready for review.

Copy link
Member

@peppy peppy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mods are not displayed correctly on tournament map pool screen.
2 participants