From d3dc791a414678417b53e19e281f4a6bd28e5f67 Mon Sep 17 00:00:00 2001 From: MayNL Date: Mon, 22 Jun 2026 11:02:21 -0400 Subject: [PATCH] Add exception check for empty texture --- PCK-Studio/Controls/Editor/PckEditor.cs | 11 +++++------ PckStudio.Core/Extensions/PckAssetExtensions.cs | 4 ++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/PCK-Studio/Controls/Editor/PckEditor.cs b/PCK-Studio/Controls/Editor/PckEditor.cs index 0d9a932a..d3fd651f 100644 --- a/PCK-Studio/Controls/Editor/PckEditor.cs +++ b/PCK-Studio/Controls/Editor/PckEditor.cs @@ -1118,7 +1118,7 @@ namespace PckStudio.Controls previewPictureBox.Image = img; labelImageSize.Text = $"{previewPictureBox.Image.Size.Width}x{previewPictureBox.Image.Size.Height}"; } - catch(System.ArgumentException ex) + catch(Exception ex) { previewPictureBox.Image = Resources.NoImageFound; MessageBox.Show(this, "Not a valid .PNG or .TGA image or invalid image data found"); @@ -1803,11 +1803,10 @@ namespace PckStudio.Controls { TreeNode node = treeViewMain.SelectedNode; - // abb = "Abbreviated Path" - string abbPath = Path.GetDirectoryName(asset.Filename); - int startIndex = abbPath.IndexOf(node.Text); - abbPath = abbPath.Substring(startIndex, abbPath.Length - startIndex); - string finalPath = ($"{outPath}/{abbPath}/").Replace('\\', '/'); + string abbreviatedPath = Path.GetDirectoryName(asset.Filename); + int startIndex = abbreviatedPath.IndexOf(node.Text); + abbreviatedPath = abbreviatedPath.Substring(startIndex, abbreviatedPath.Length - startIndex); + string finalPath = ($"{outPath}/{abbreviatedPath}/").Replace('\\', '/'); if (!Directory.Exists(finalPath)) Directory.CreateDirectory(finalPath); diff --git a/PckStudio.Core/Extensions/PckAssetExtensions.cs b/PckStudio.Core/Extensions/PckAssetExtensions.cs index 9f38b647..59f7bc09 100644 --- a/PckStudio.Core/Extensions/PckAssetExtensions.cs +++ b/PckStudio.Core/Extensions/PckAssetExtensions.cs @@ -45,6 +45,10 @@ namespace PckStudio.Core.Extensions { throw new Exception("Asset is not suitable to contain image data."); } + if (asset.Size == 0) + { + throw new Exception("Asset is has no data."); + } return asset.GetDeserializedData(ImageDeserializer.DefaultDeserializer); }