From 0d44b5af90d606657e63c9c386574dcd5e18c89f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 31 Oct 2023 17:36:23 +0900 Subject: [PATCH] Fix potential texture corruption when cropping gameplay textures of weird aspet ratios Closes https://github.com/ppy/osu/issues/25273. --- osu.Game/Skinning/LegacySkinExtensions.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/osu.Game/Skinning/LegacySkinExtensions.cs b/osu.Game/Skinning/LegacySkinExtensions.cs index 62197fa8a7..a8ec67d98b 100644 --- a/osu.Game/Skinning/LegacySkinExtensions.cs +++ b/osu.Game/Skinning/LegacySkinExtensions.cs @@ -115,7 +115,18 @@ namespace osu.Game.Skinning maxSize *= texture.ScaleAdjust; - var croppedTexture = texture.Crop(new RectangleF(texture.Width / 2f - maxSize.X / 2f, texture.Height / 2f - maxSize.Y / 2f, maxSize.X, maxSize.Y)); + // Importantly, check per-axis for the minimum dimension to avoid accidentally inflating + // textures with weird aspect ratios. + float newWidth = Math.Min(texture.Width, maxSize.X); + float newHeight = Math.Min(texture.Height, maxSize.Y); + + var croppedTexture = texture.Crop(new RectangleF( + texture.Width / 2f - newWidth / 2f, + texture.Height / 2f - newHeight / 2f, + newWidth, + newHeight + )); + croppedTexture.ScaleAdjust = texture.ScaleAdjust; return croppedTexture; }