Browse Source

Fixed selection crash

flabbet 2 years ago
parent
commit
0fdfc9448d

+ 3 - 0
src/PixiEditor.DrawingApi.Core/Surface/Vector/VectorPath.cs

@@ -48,6 +48,8 @@ public class VectorPath : NativeObject
     public bool IsEmpty => VerbCount == 0;
     public bool IsEmpty => VerbCount == 0;
     public RectD Bounds => DrawingBackendApi.Current.PathImplementation.GetBounds(this);
     public RectD Bounds => DrawingBackendApi.Current.PathImplementation.GetBounds(this);
     
     
+    public bool IsDisposed { get; private set; }
+    
     public VectorPath(IntPtr nativePointer) : base(nativePointer)
     public VectorPath(IntPtr nativePointer) : base(nativePointer)
     {
     {
     }
     }
@@ -67,6 +69,7 @@ public class VectorPath : NativeObject
     public override void Dispose()
     public override void Dispose()
     {
     {
         DrawingBackendApi.Current.PathImplementation.Dispose(this);
         DrawingBackendApi.Current.PathImplementation.Dispose(this);
+        IsDisposed = true;
     }
     }
 
 
     public void Reset()
     public void Reset()

+ 4 - 4
src/PixiEditor.DrawingApi.Skia/Implementations/SkiaPathImplementation.cs

@@ -31,8 +31,8 @@ namespace PixiEditor.DrawingApi.Skia.Implementations
 
 
         public void Dispose(VectorPath path)
         public void Dispose(VectorPath path)
         {
         {
+            if (path.IsDisposed) return;
             ManagedInstances[path.ObjectPointer].Dispose();
             ManagedInstances[path.ObjectPointer].Dispose();
-            
             ManagedInstances.Remove(path.ObjectPointer);
             ManagedInstances.Remove(path.ObjectPointer);
         }
         }
 
 
@@ -74,14 +74,14 @@ namespace PixiEditor.DrawingApi.Skia.Implementations
         public IntPtr Create()
         public IntPtr Create()
         {
         {
             SKPath path = new SKPath();
             SKPath path = new SKPath();
-            ManagedInstances[path.Handle] = path;
+            ManagedInstances.Add(path.Handle, path);
             return path.Handle;
             return path.Handle;
         }
         }
 
 
         public IntPtr Clone(VectorPath other)
         public IntPtr Clone(VectorPath other)
         {
         {
             SKPath path = new SKPath(ManagedInstances[other.ObjectPointer]);
             SKPath path = new SKPath(ManagedInstances[other.ObjectPointer]);
-            ManagedInstances[path.Handle] = path;
+            ManagedInstances.Add(path.Handle, path);
             return path.Handle;
             return path.Handle;
         }
         }
 
 
@@ -140,7 +140,7 @@ namespace PixiEditor.DrawingApi.Skia.Implementations
         public VectorPath Op(VectorPath vectorPath, VectorPath ellipsePath, VectorPathOp pathOp)
         public VectorPath Op(VectorPath vectorPath, VectorPath ellipsePath, VectorPathOp pathOp)
         {
         {
             SKPath skPath = ManagedInstances[vectorPath.ObjectPointer].Op(ManagedInstances[ellipsePath.ObjectPointer], (SKPathOp)pathOp);
             SKPath skPath = ManagedInstances[vectorPath.ObjectPointer].Op(ManagedInstances[ellipsePath.ObjectPointer], (SKPathOp)pathOp);
-            ManagedInstances[skPath.Handle] = skPath;
+            ManagedInstances.Add(skPath.Handle, skPath);
             return new VectorPath(skPath.Handle);
             return new VectorPath(skPath.Handle);
         }
         }
 
 

+ 1 - 1
src/PixiEditor/ViewModels/SubViewModels/Document/DocumentViewModel.cs

@@ -389,7 +389,7 @@ internal class DocumentViewModel : NotifyableObject
 
 
     public void InternalUpdateSelectionPath(VectorPath vectorPath)
     public void InternalUpdateSelectionPath(VectorPath vectorPath)
     {
     {
-        (VectorPath? toDispose, this.selectionPath) = (this.selectionPath, selectionPath);
+        (VectorPath? toDispose, this.selectionPath) = (this.selectionPath, vectorPath);
         toDispose.Dispose();
         toDispose.Dispose();
         RaisePropertyChanged(nameof(SelectionPathBindable));
         RaisePropertyChanged(nameof(SelectionPathBindable));
     }
     }