diff --git a/Ryujinx.Graphics.Gpu/Image/Texture.cs b/Ryujinx.Graphics.Gpu/Image/Texture.cs index cc7e7bf603..28ad3f7798 100644 --- a/Ryujinx.Graphics.Gpu/Image/Texture.cs +++ b/Ryujinx.Graphics.Gpu/Image/Texture.cs @@ -253,7 +253,7 @@ namespace Ryujinx.Graphics.Gpu.Image if (!_context.Capabilities.SupportsAstcCompression && _info.FormatInfo.Format.IsAstc()) { - data = AstcDecoder.DecodeToRgba8( + if (!AstcDecoder.TryDecodeToRgba8( data, _info.FormatInfo.BlockWidth, _info.FormatInfo.BlockHeight, @@ -261,7 +261,13 @@ namespace Ryujinx.Graphics.Gpu.Image _info.Width, _info.Height, _depth, - _info.Levels); + _info.Levels, + out Span decoded)) + { + // TODO: Error. + } + + data = decoded; } HostTexture.SetData(data); diff --git a/Ryujinx.Graphics.Texture/Astc/AstcDecoder.cs b/Ryujinx.Graphics.Texture/Astc/AstcDecoder.cs index 0b8172f736..41db7e05ab 100644 --- a/Ryujinx.Graphics.Texture/Astc/AstcDecoder.cs +++ b/Ryujinx.Graphics.Texture/Astc/AstcDecoder.cs @@ -47,16 +47,19 @@ namespace Ryujinx.Graphics.Texture.Astc } } - public static Span DecodeToRgba8( - Span data, - int blockWidth, - int blockHeight, - int blockDepth, - int width, - int height, - int depth, - int levels) + public static bool TryDecodeToRgba8( + Span data, + int blockWidth, + int blockHeight, + int blockDepth, + int width, + int height, + int depth, + int levels, + out Span decoded) { + bool success = true; + using (MemoryStream inputStream = new MemoryStream(data.ToArray())) { BinaryReader binReader = new BinaryReader(inputStream); @@ -85,7 +88,14 @@ namespace Ryujinx.Graphics.Texture.Astc { int[] decompressedData = new int[144]; - DecompressBlock(binReader.ReadBytes(0x10), decompressedData, blockWidth, blockHeight); + try + { + DecompressBlock(binReader.ReadBytes(0x10), decompressedData, blockWidth, blockHeight); + } + catch (Exception) + { + success = false; + } int decompressedWidth = Math.Min(blockWidth, width - i); int decompressedHeight = Math.Min(blockHeight, height - j); @@ -112,9 +122,11 @@ namespace Ryujinx.Graphics.Texture.Astc height = Math.Max(1, height >> 1); } - return outputStream.ToArray(); + decoded = outputStream.ToArray(); } } + + return success; } public static bool DecompressBlock(