From 22f31bfbca24aa2b91ef6d0bb14dc2f03b4aa596 Mon Sep 17 00:00:00 2001 From: GZHYBFHHJ Date: Thu, 7 Mar 2024 23:04:07 +0800 Subject: [PATCH 1/2] Fix NullReferenceException in RefreshZoom --- ABStudio/Forms/SpritesheetEditor.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ABStudio/Forms/SpritesheetEditor.cs b/ABStudio/Forms/SpritesheetEditor.cs index 789bc4f..9ff7b7e 100644 --- a/ABStudio/Forms/SpritesheetEditor.cs +++ b/ABStudio/Forms/SpritesheetEditor.cs @@ -69,6 +69,8 @@ private static string[] GenerateSaveExtensionTable(bool allowPVR) public SpritesheetEditor(string path, DATFile file) { + spritesheet = new Bitmap(1, 1); + InitializeComponent(); originalPath = path; From 560bffe9cd67b9d226c03db08317f1174010ab98 Mon Sep 17 00:00:00 2001 From: GZHYBFHHJ Date: Wed, 10 Apr 2024 20:55:28 +0800 Subject: [PATCH 2/2] Update SpritesheetEditor.cs --- ABStudio/Forms/SpritesheetEditor.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ABStudio/Forms/SpritesheetEditor.cs b/ABStudio/Forms/SpritesheetEditor.cs index 9ff7b7e..0a19b7f 100644 --- a/ABStudio/Forms/SpritesheetEditor.cs +++ b/ABStudio/Forms/SpritesheetEditor.cs @@ -69,8 +69,6 @@ private static string[] GenerateSaveExtensionTable(bool allowPVR) public SpritesheetEditor(string path, DATFile file) { - spritesheet = new Bitmap(1, 1); - InitializeComponent(); originalPath = path; @@ -499,6 +497,14 @@ private void LoadBitmap(string path=null) private void RefreshZoom() { + if (spritesheet == null) + { + // On some computers, this method may be called by `InitializeComponent` in the class constructor. + // In this case, `spritesheet` is null, which can cause NullReferenceException to be thrown. + + spritesheet = new Bitmap(1, 1); + } + float w = spritesheet.Width * zoom; float h = spritesheet.Height * zoom;