Browse Source

Null checks

Krzysztof Krysiński 3 tuần trước cách đây
mục cha
commit
233efbd63a

+ 1 - 1
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Shapes/Data/PointsVectorData.cs

@@ -16,7 +16,7 @@ public class PointsVectorData : ShapeVectorData
         Points = new List<VecD>(points);
     }
 
-    public override RectD GeometryAABB => new RectD(Points.Min(p => p.X), Points.Min(p => p.Y), Points.Max(p => p.X),
+    public override RectD GeometryAABB => Points == null || Points.Count == 0 ? RectD.Empty : new RectD(Points.Min(p => p.X), Points.Min(p => p.Y), Points.Max(p => p.X),
         Points.Max(p => p.Y));
 
     public override RectD VisualAABB => GeometryAABB;

+ 3 - 0
src/PixiEditor.ChangeableDocument/Changes/NodeGraph/NodeOperations.cs

@@ -115,6 +115,9 @@ public static class NodeOperations
     {
         List<IChangeInfo> changes = new();
         IOutputProperty? previouslyConnected = null;
+
+        if(parentInput == null) return changes;
+
         if (parentInput.Connection != null)
         {
             previouslyConnected = parentInput.Connection;

+ 2 - 2
src/PixiEditor.ChangeableDocument/Changes/Root/ClipCanvas_Change.cs

@@ -45,8 +45,8 @@ internal class ClipCanvas_Change : ResizeBasedChangeBase
         VecI size = (VecI)newBounds.Size.Ceiling();
         
         target.Size = size;
-        target.VerticalSymmetryAxisX = Math.Clamp(_originalVerAxisX, 0, target.Size.X);
-        target.HorizontalSymmetryAxisY = Math.Clamp(_originalHorAxisY, 0, target.Size.Y);
+        target.VerticalSymmetryAxisX = Math.Clamp(_originalVerAxisX, 0, Math.Max(target.Size.X, 1));
+        target.HorizontalSymmetryAxisY = Math.Clamp(_originalHorAxisY, 0, Math.Max(target.Size.Y, 1));
         
         target.ForEveryMember((member) =>
         {

+ 3 - 1
src/PixiEditor/ViewModels/SubViewModels/LayersViewModel.cs

@@ -235,6 +235,9 @@ internal class LayersViewModel : SubViewModel<ViewModelMain>
         AnalyticsTrack = true)]
     public void DuplicateMember()
     {
+        if (Owner.DocumentManagerSubViewModel.ActiveDocument?.SelectedStructureMember == null)
+            return;
+
         var member = Owner.DocumentManagerSubViewModel.ActiveDocument?.SelectedStructureMember;
 
         member.Document.Operations.DuplicateMember(member.Id);
@@ -379,7 +382,6 @@ internal class LayersViewModel : SubViewModel<ViewModelMain>
         nameof(ViewModelMain.DocumentManagerSubViewModel.ActiveDocument),
         nameof(ViewModelMain.DocumentManagerSubViewModel.ActiveDocument.SelectedStructureMember),
         nameof(ViewModelMain.DocumentManagerSubViewModel.ActiveDocument.SelectedStructureMember.HasMaskBindable))]
-
     public bool ActiveMemberHasApplyableMask() =>
         (Owner.DocumentManagerSubViewModel.ActiveDocument?.SelectedStructureMember?.HasMaskBindable ?? false)
         && Owner.DocumentManagerSubViewModel.ActiveDocument?.SelectedStructureMember is IRasterLayerHandler;

+ 8 - 4
src/PixiEditor/Views/Dialogs/ExportFilePopup.axaml.cs

@@ -247,10 +247,14 @@ internal partial class ExportFilePopup : PixiEditorPopup
     protected override void OnClosing(WindowClosingEventArgs e)
     {
         base.OnClosing(e);
-        videoPreviewTimer.Stop();
-        videoPreviewTimer.Tick -= OnVideoPreviewTimerOnTick;
-        videoPreviewTimer = null;
-        cancellationTokenSource.Cancel();
+        if (videoPreviewTimer != null)
+        {
+            videoPreviewTimer.Stop();
+            videoPreviewTimer.Tick -= OnVideoPreviewTimerOnTick;
+            videoPreviewTimer = null;
+        }
+
+        cancellationTokenSource?.Cancel();
 
         ExportPreview?.Dispose();
 

+ 2 - 2
src/PixiEditor/Views/Nodes/Properties/NodePropertyView.cs

@@ -91,12 +91,12 @@ public abstract class NodePropertyView : UserControl
 
     protected void HideSocket(bool hideInputSocket, bool hideOutputSocket)
     {
-        if (hideInputSocket)
+        if (hideInputSocket && InputSocket is not null)
         {
             InputSocket.IsVisible = false;
         }
 
-        if (hideOutputSocket)
+        if (hideOutputSocket && OutputSocket is not null)
         {
             OutputSocket.IsVisible = false;
         }

+ 10 - 2
src/PixiEditor/Views/Overlays/Handles/Handle.cs

@@ -1,4 +1,5 @@
-using Avalonia;
+using System;
+using Avalonia;
 using Avalonia.Controls;
 using Avalonia.Controls.Shapes;
 using Avalonia.Input;
@@ -76,7 +77,14 @@ public abstract class Handle : IHandle
         {
             if (shape is string path)
             {
-                return new PathVectorData(VectorPath.FromSvgPath(path));
+                try
+                {
+                    return new PathVectorData(VectorPath.FromSvgPath(path));
+                }
+                catch (Exception ex)
+                {
+                    return new PathVectorData(VectorPath.FromSvgPath("M 0 0 L 1 0 M 0 0 L 0 1"));
+                }
             }
 
             if (shape is VectorPathResource resource)