Browse Source

Fixed a few crashes

flabbet 4 years ago
parent
commit
fc6df66a7c

+ 7 - 2
PixiEditor/Models/Layers/LayerStructure.cs

@@ -300,8 +300,13 @@ namespace PixiEditor.Models.Layers
         /// <returns>List of layer guids.</returns>
         private List<Guid> GetGroupLayerGuids(GuidStructureItem group)
         {
-            Layer layerTop = Owner.Layers.First(x => x.LayerGuid == group.EndLayerGuid);
-            Layer layerBottom = Owner.Layers.First(x => x.LayerGuid == group.StartLayerGuid);
+            Layer? layerTop = Owner.Layers.FirstOrDefault(x => x.LayerGuid == group.EndLayerGuid);
+            Layer? layerBottom = Owner.Layers.FirstOrDefault(x => x.LayerGuid == group.StartLayerGuid);
+
+            if(layerTop == null || layerBottom == null)
+            {
+                return new List<Guid>();
+            }
 
             int indexTop = Owner.Layers.IndexOf(layerTop);
             int indexBottom = Owner.Layers.IndexOf(layerBottom);

+ 4 - 1
PixiEditor/Views/UserControls/LayerGroupControl.xaml.cs

@@ -107,7 +107,10 @@ namespace PixiEditor.Views.UserControls
         public void GeneratePreviewImage()
         {
             var layers = LayersViewModel.Owner.BitmapManager.ActiveDocument.LayerStructure.GetGroupLayers(GroupData);
-            PreviewImage = BitmapUtils.GeneratePreviewBitmap(layers, 25, 25, true);
+            if (layers.Count > 0)
+            {
+                PreviewImage = BitmapUtils.GeneratePreviewBitmap(layers, 25, 25, true);
+            }
         }
 
         private static void GroupDataChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)