Browse Source

Fixed crash on corrupt document

CPKreuz 1 year ago
parent
commit
be5f4e31da

+ 7 - 1
src/PixiEditor/Models/UserData/RecentlyOpenedDocument.cs

@@ -36,7 +36,13 @@ internal class RecentlyOpenedDocument : ObservableObject
     public bool Corrupt
     public bool Corrupt
     {
     {
         get => corrupt;
         get => corrupt;
-        set => SetProperty(ref corrupt, value);
+        set
+        {
+            if (SetProperty(ref corrupt, value))
+            {
+                this.OnPropertyChanged(FileExtension);
+            }
+        }
     }
     }
 
 
     public string FileName => Path.GetFileNameWithoutExtension(filePath);
     public string FileName => Path.GetFileNameWithoutExtension(filePath);

+ 15 - 5
src/PixiEditor/Views/Visuals/PixiFilePreviewImage.cs

@@ -58,13 +58,17 @@ internal class PixiFilePreviewImage : SurfaceControl
     {
     {
         var surface = LoadPreviewSurface(path);
         var surface = LoadPreviewSurface(path);
         
         
-        Dispatcher.UIThread.Post(() => SetImage(surface, surface.Size));
+        Dispatcher.UIThread.Post(() => SetImage(surface));
     }
     }
 
 
-    private void SetImage(Surface surface, VecI size)
+    private void SetImage(Surface? surface)
     {
     {
-        Surface = surface;
-        ImageSize = size;
+        Surface = surface!;
+
+        if (surface != null)
+        {
+            ImageSize = surface.Size;
+        }
     }
     }
 
 
     private static void OnFilePathChanged(PixiFilePreviewImage previewImage, AvaloniaPropertyChangedEventArgs args)
     private static void OnFilePathChanged(PixiFilePreviewImage previewImage, AvaloniaPropertyChangedEventArgs args)
@@ -91,7 +95,12 @@ internal class PixiFilePreviewImage : SurfaceControl
         {
         {
             try
             try
             {
             {
-                return Importer.GetPreviewSurface(filePath);
+                var result = Importer.GetPreviewSurface(filePath);
+
+                if (result == null)
+                {
+                    SetCorrupt();
+                }
             }
             }
             catch
             catch
             {
             {
@@ -121,6 +130,7 @@ internal class PixiFilePreviewImage : SurfaceControl
 
 
         return null;
         return null;
 
 
+        // TODO: This does not actually set the dot to gray
         void SetCorrupt()
         void SetCorrupt()
         {
         {
             Dispatcher.UIThread.Post(() => Corrupt = true);
             Dispatcher.UIThread.Post(() => Corrupt = true);