Browse Source

Some more disposing

Krzysztof Krysiński 5 months ago
parent
commit
d71412f4d3

+ 17 - 9
src/ChunkyImageLib/Chunk.cs

@@ -31,7 +31,7 @@ public class Chunk : IDisposable
             {
                 throw new ObjectDisposedException("Chunk has been disposed");
             }
-            
+
             return internalSurface;
         }
     }
@@ -47,10 +47,11 @@ public class Chunk : IDisposable
     public ChunkResolution Resolution { get; }
 
     public ColorSpace ColorSpace { get; }
-    
+
     public bool Disposed => returned;
 
     private Surface internalSurface;
+
     private Chunk(ChunkResolution resolution, ColorSpace colorSpace)
     {
         int size = resolution.PixelSize();
@@ -66,7 +67,12 @@ public class Chunk : IDisposable
     /// </summary>
     public static Chunk Create(ColorSpace chunkCs, ChunkResolution resolution = ChunkResolution.Full)
     {
-        var chunk = ChunkPool.Instance.Get(resolution, chunkCs) ?? new Chunk(resolution, chunkCs);
+        var chunk = ChunkPool.Instance.Get(resolution, chunkCs);
+        if (chunk == null || chunk.Disposed)
+        {
+            chunk = new Chunk(resolution, chunkCs);
+        }
+
         chunk.returned = false;
         Interlocked.Increment(ref chunkCounter);
         return chunk;
@@ -81,18 +87,20 @@ public class Chunk : IDisposable
     {
         surface.Canvas.DrawSurface(Surface.DrawingSurface, (float)pos.X, (float)pos.Y, paint);
     }
-    
+
     public unsafe RectI? FindPreciseBounds(RectI? passedSearchRegion = null)
     {
         RectI? bounds = null;
-        if (returned) 
+        if (returned)
             return bounds;
 
-        if (passedSearchRegion is not null && !new RectI(VecI.Zero, Surface.Size).ContainsInclusive(passedSearchRegion.Value))
-            throw new ArgumentException("Passed search region lies outside of the chunk's surface", nameof(passedSearchRegion));
+        if (passedSearchRegion is not null &&
+            !new RectI(VecI.Zero, Surface.Size).ContainsInclusive(passedSearchRegion.Value))
+            throw new ArgumentException("Passed search region lies outside of the chunk's surface",
+                nameof(passedSearchRegion));
 
         RectI searchRegion = passedSearchRegion ?? new RectI(VecI.Zero, Surface.Size);
-        
+
         ulong* ptr = (ulong*)Surface.PixelBuffer;
         for (int y = searchRegion.Top; y < searchRegion.Bottom; y++)
         {
@@ -108,7 +116,7 @@ public class Chunk : IDisposable
                 }
             }
         }
-        
+
         return bounds;
     }
 

+ 1 - 1
src/Drawie

@@ -1 +1 @@
-Subproject commit 551f1fcb19788e0e2e2dd6531adf65f18f157080
+Subproject commit a666f1d1028e1e625d34a7e51fbd91261ee424c7

+ 5 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/LayerNode.cs

@@ -150,6 +150,11 @@ public abstract class LayerNode : StructureNode, IReadOnlyLayerNode, IClipSource
             DrawWithoutFilters(ctx, targetSurface, finalPaint);
         }
 
+        if (finalPaint != blendPaint)
+        {
+            finalPaint.Dispose();
+        }
+
         if (targetSurface != workingSurface)
         {
             workingSurface.Canvas.DrawSurface(targetSurface, 0, 0, blendPaint);

+ 1 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/StructureNode.cs

@@ -354,5 +354,6 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
         Output.Value = null;
         maskPaint.Dispose();
         blendPaint.Dispose();
+        maskPreviewPaint.Dispose();
     }
 }

+ 5 - 3
src/PixiEditor.ChangeableDocument/Changes/Drawing/LineBasedPen_UpdateableChange.cs

@@ -21,6 +21,7 @@ internal class LineBasedPen_UpdateableChange : UpdateableChange
     private float hardness;
     private float spacing = 1;
     private readonly Paint srcPaint = new Paint() { BlendMode = BlendMode.Src };
+    private Paintable? finalPaintable;
 
     private CommittedChunkStorage? storedChunks;
     private readonly List<VecI> points = new();
@@ -103,7 +104,7 @@ internal class LineBasedPen_UpdateableChange : UpdateableChange
 
             lastPos = point;
             var rect = new RectI(point - new VecI((int)(strokeWidth / 2f)), new VecI((int)strokeWidth));
-            Paintable finalPaintable = color;
+            finalPaintable = color;
 
             if (!squareBrush)
             {
@@ -135,7 +136,7 @@ internal class LineBasedPen_UpdateableChange : UpdateableChange
         if (points.Count == 1)
         {
             var rect = new RectI(points[0] - new VecI((int)(strokeWidth / 2f)), new VecI((int)strokeWidth));
-            Paintable finalPaintable = color;
+            finalPaintable = color;
 
             if (!squareBrush)
             {
@@ -169,7 +170,7 @@ internal class LineBasedPen_UpdateableChange : UpdateableChange
 
             lastPos = points[i];
             var rect = new RectI(points[i] - new VecI((int)(strokeWidth / 2f)), new VecI((int)strokeWidth));
-            Paintable? finalPaintable = color;
+            finalPaintable = color;
 
             if (!squareBrush)
             {
@@ -250,5 +251,6 @@ internal class LineBasedPen_UpdateableChange : UpdateableChange
     public override void Dispose()
     {
         storedChunks?.Dispose();
+        srcPaint.Dispose();
     }
 }

+ 1 - 0
src/PixiEditor/Views/Rendering/Scene.cs

@@ -280,6 +280,7 @@ internal class Scene : Zoombox.Zoombox, ICustomHitTest
 
         RectD operationSurfaceRectToRender = new RectD(0, 0, dirtyBounds.Width, dirtyBounds.Height);
         float checkerScale = (float)ZoomToViewportConverter.ZoomToViewport(16, Scale) * 0.5f;
+        checkerPaint?.Shader?.Dispose();
         checkerPaint?.Dispose();
         checkerPaint = new Paint
         {