diff --git a/UndertaleModLib/Models/UndertaleEmbeddedTexture.cs b/UndertaleModLib/Models/UndertaleEmbeddedTexture.cs
index 529ccb19b..019562ebe 100644
--- a/UndertaleModLib/Models/UndertaleEmbeddedTexture.cs
+++ b/UndertaleModLib/Models/UndertaleEmbeddedTexture.cs
@@ -316,21 +316,33 @@ public GMImage Image
///
/// The width of the texture.
///
- public int Width => _image.Width;
+ ///
+ /// In the case of an invalid or missing image, this will always be -1.
+ ///
+ public int Width => _image?.Width ?? -1;
///
/// The height of the texture.
///
- public int Height => _image.Height;
+ ///
+ /// In the case of an invalid or missing image, this will always be -1.
+ ///
+ public int Height => _image?.Height ?? -1;
///
/// Whether this texture uses the QOI format.
///
+ ///
+ /// In the case of an invalid or missing image, this will always be .
+ ///
public bool FormatQOI => _image.Format is GMImage.ImageFormat.Qoi or GMImage.ImageFormat.Bz2Qoi;
///
/// Whether this texture uses the BZ2 format. (Always used in combination with QOI.)
///
+ ///
+ /// In the case of an invalid or missing image, this will always be .
+ ///
public bool FormatBZ2 => _image.Format is GMImage.ImageFormat.Bz2Qoi;
///
diff --git a/UndertaleModTool/Editors/UndertaleEmbeddedTextureEditor.xaml.cs b/UndertaleModTool/Editors/UndertaleEmbeddedTextureEditor.xaml.cs
index 98eaa5377..8950e0885 100644
--- a/UndertaleModTool/Editors/UndertaleEmbeddedTextureEditor.xaml.cs
+++ b/UndertaleModTool/Editors/UndertaleEmbeddedTextureEditor.xaml.cs
@@ -69,6 +69,12 @@ public UndertaleEmbeddedTextureEditor()
private void UpdateImage(UndertaleEmbeddedTexture texture)
{
+ if (texture.TextureData?.Image is null)
+ {
+ TexturePageImage.Source = null;
+ return;
+ }
+
GMImage image = texture.TextureData.Image;
BitmapSource bitmap = mainWindow.GetBitmapSourceForImage(image);
TexturePageImage.Source = bitmap;
@@ -88,8 +94,13 @@ private void SwitchDataContext(object sender, DependencyPropertyChangedEventArgs
{
_textureDataContext.PropertyChanged -= ReloadTextureImage;
}
+
_textureDataContext = texture.TextureData;
- _textureDataContext.PropertyChanged += ReloadTextureImage;
+
+ if (_textureDataContext is not null)
+ {
+ _textureDataContext.PropertyChanged += ReloadTextureImage;
+ }
}
private void ReloadTextureImage(object sender, PropertyChangedEventArgs e)
diff --git a/UndertaleModTool/Editors/UndertaleTexturePageItemEditor.xaml.cs b/UndertaleModTool/Editors/UndertaleTexturePageItemEditor.xaml.cs
index b6817b0cc..1724def29 100644
--- a/UndertaleModTool/Editors/UndertaleTexturePageItemEditor.xaml.cs
+++ b/UndertaleModTool/Editors/UndertaleTexturePageItemEditor.xaml.cs
@@ -40,6 +40,13 @@ public UndertaleTexturePageItemEditor()
private void UpdateImages(UndertaleTexturePageItem item)
{
+ if (item.TexturePage?.TextureData?.Image is null)
+ {
+ ItemTextureBGImage.Source = null;
+ ItemTextureImage.Source = null;
+ return;
+ }
+
GMImage image = item.TexturePage.TextureData.Image;
BitmapSource bitmap = mainWindow.GetBitmapSourceForImage(image);
ItemTextureBGImage.Source = bitmap;
@@ -68,8 +75,12 @@ private void SwitchDataContext(object sender, DependencyPropertyChangedEventArgs
{
_textureDataContext.PropertyChanged -= ReloadTextureImage;
}
- _textureDataContext = item.TexturePage.TextureData;
- _textureDataContext.PropertyChanged += ReloadTextureImage;
+
+ if (item.TexturePage?.TextureData is not null)
+ {
+ _textureDataContext = item.TexturePage.TextureData;
+ _textureDataContext.PropertyChanged += ReloadTextureImage;
+ }
}
private void ReloadTexturePage(object sender, PropertyChangedEventArgs e)