1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 03:42:57 +08:00

Fix potential texture corruption when cropping gameplay textures of weird aspet ratios

Closes https://github.com/ppy/osu/issues/25273.
This commit is contained in:
Dean Herbert 2023-10-31 17:36:23 +09:00
parent 84fb0c63e5
commit 0d44b5af90
No known key found for this signature in database

View File

@ -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;
}