Browse Source

#310 prevent crash

ouadsecond 3 years ago
parent
commit
15dffc1119
1 changed files with 9 additions and 6 deletions
  1. 9 6
      PixiEditor/ViewModels/SubViewModels/Main/LayersViewModel.cs

+ 9 - 6
PixiEditor/ViewModels/SubViewModels/Main/LayersViewModel.cs

@@ -247,14 +247,17 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
 
         public void RenameLayer(object parameter)
         {
-            int? index = (int?)parameter;
+          if (Owner.BitmapManager.ActiveDocument == null)
+            return;
 
-            if (index == null)
-            {
-                index = Owner.BitmapManager.ActiveDocument.Layers.IndexOf(Owner.BitmapManager.ActiveDocument.ActiveLayer);
-            }
+          int? index = (int?)parameter;
+
+          if (index == null)
+          {
+            index = Owner.BitmapManager.ActiveDocument.Layers.IndexOf(Owner.BitmapManager.ActiveDocument.ActiveLayer);
+          }
 
-            Owner.BitmapManager.ActiveDocument.Layers[(int)index].IsRenaming = true;
+          Owner.BitmapManager.ActiveDocument.Layers[(int)index].IsRenaming = true;
         }
 
         public bool CanRenameLayer(object parameter)