From 58c74e839c2193ad2119d4e5b7337f16826b56f4 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Mon, 30 Jan 2023 22:22:39 +0100 Subject: [PATCH] Maybe improve error handling when unable to create mipmaps. --- Penumbra/Import/Textures/CombinedTexture.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Penumbra/Import/Textures/CombinedTexture.cs b/Penumbra/Import/Textures/CombinedTexture.cs index c3065186..3a8762d4 100644 --- a/Penumbra/Import/Textures/CombinedTexture.cs +++ b/Penumbra/Import/Textures/CombinedTexture.cs @@ -130,9 +130,21 @@ public partial class CombinedTexture : IDisposable } private static ScratchImage AddMipMaps( ScratchImage input, bool mipMaps ) - => mipMaps - ? input.GenerateMipMaps( Math.Min( 13, 1 + BitOperations.Log2( ( uint )Math.Max( input.Meta.Width, input.Meta.Height ) ) ), FilterFlags.SeparateAlpha ) - : input; + { + if( !mipMaps ) + { + return input; + } + + var numMips = Math.Min( 13, 1 + BitOperations.Log2( ( uint )Math.Max( input.Meta.Width, input.Meta.Height ) ) ); + var ec = input.GenerateMipMaps( out var ret, numMips, FilterFlags.SeparateAlpha ); + if (ec != ErrorCode.Ok) + { + throw new Exception( $"Could not create the requested {numMips} mip maps, maybe retry with the top-right checkbox unchecked:\n{ec}" ); + } + + return ret; + } private static ScratchImage CreateUncompressed( ScratchImage input, bool mipMaps ) {