From 03a5f94924f3bb19fc456ba4a0070cfd764a3fae Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Tue, 30 Jan 2024 07:16:24 -0800 Subject: [PATCH] Improve failure mode when FNA3D fails to decode an image --- src/Graphics/Texture2D.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Graphics/Texture2D.cs b/src/Graphics/Texture2D.cs index 1b09bcbd..786ccadc 100644 --- a/src/Graphics/Texture2D.cs +++ b/src/Graphics/Texture2D.cs @@ -419,6 +419,8 @@ public static Texture2D FromStream(GraphicsDevice graphicsDevice, Stream stream) out height, out len ); + if ((pixels == IntPtr.Zero) || (width <= 0) || (height <= 0)) + throw new Exception("Decoding image failed!"); Texture2D result = new Texture2D( graphicsDevice, @@ -458,6 +460,8 @@ bool zoom height, zoom ); + if ((pixels == IntPtr.Zero) || (realWidth <= 0) || (realHeight <= 0)) + throw new Exception("Decoding image failed!"); Texture2D result = new Texture2D( graphicsDevice,