From fd495e87f74d5e6b76d67b9fa2865378b95c562b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 25 Jan 2023 18:37:58 +0100 Subject: [PATCH] Fix `GetAsync()` not limiting texture dimensions --- .../MaxDimensionLimitedTextureLoaderStore.cs | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/osu.Game/Skinning/MaxDimensionLimitedTextureLoaderStore.cs b/osu.Game/Skinning/MaxDimensionLimitedTextureLoaderStore.cs index 503add45ed..f15097a169 100644 --- a/osu.Game/Skinning/MaxDimensionLimitedTextureLoaderStore.cs +++ b/osu.Game/Skinning/MaxDimensionLimitedTextureLoaderStore.cs @@ -35,6 +35,25 @@ namespace osu.Game.Skinning if (textureUpload == null) return null!; + return limitTextureUploadSize(textureUpload); + } + + public async Task GetAsync(string name, CancellationToken cancellationToken = new CancellationToken()) + { + // NRT not enabled on framework side classes (IResourceStore / TextureLoaderStore), welp. + if (textureStore == null) + return null!; + + var textureUpload = await textureStore.GetAsync(name, cancellationToken).ConfigureAwait(false); + + if (textureUpload == null) + return null!; + + return await Task.Run(() => limitTextureUploadSize(textureUpload), cancellationToken).ConfigureAwait(false); + } + + private TextureUpload limitTextureUploadSize(TextureUpload textureUpload) + { // So there's a thing where some users have taken it upon themselves to create skin elements of insane dimensions. // To the point where GPUs cannot load the textures (along with most image editor apps). // To work around this, let's look out for any stupid images and shrink them down into a usable size. @@ -58,10 +77,6 @@ namespace osu.Game.Skinning return textureUpload; } - // TODO: remove null-forgiving operator below after texture stores are NRT-annotated framework-side - public Task GetAsync(string name, CancellationToken cancellationToken = new CancellationToken()) - => textureStore?.GetAsync(name, cancellationToken) ?? Task.FromResult(null!); - public Stream? GetStream(string name) => textureStore?.GetStream(name); public IEnumerable GetAvailableResources() => textureStore?.GetAvailableResources() ?? Array.Empty();