Browse Source

Dispose fixes and request texture thing

flabbet 1 year ago
parent
commit
2b66f8c529

+ 2 - 7
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/FilterNodes/ApplyFilterNode.cs

@@ -35,13 +35,8 @@ public class ApplyFilterNode : Node
         }
         
         _paint.SetFilters(Filter.Value);
-
-        if (_workingSurface == null || _workingSurface.Size != input.Size)
-        {
-            _workingSurface?.Dispose();
-            _workingSurface = new Texture(input.Size);
-            _workingSurface.DrawingSurface.Canvas.Clear();
-        }
+        
+        _workingSurface = RequestTexture(0, input.Size, true);
         
         _workingSurface.DrawingSurface.Canvas.DrawSurface(input.DrawingSurface, 0, 0, _paint);
 

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

@@ -123,7 +123,7 @@ public class ImageLayerNode : LayerNode, IReadOnlyImageNode
 
         if (Background.Value != null)
         {
-            Texture tempSurface = new Texture(outputWorkingSurface.Size);
+            Texture tempSurface = RequestTexture(4, outputWorkingSurface.Size, true);
             DrawBackground(tempSurface, context);
             blendPaint.BlendMode = RenderingContext.GetDrawingBlendMode(BlendMode.Value);
             tempSurface.DrawingSurface.Canvas.DrawSurface(outputWorkingSurface.DrawingSurface, 0, 0, blendPaint);

+ 3 - 3
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/MergeNode.cs

@@ -36,10 +36,10 @@ public class MergeNode : Node, IBackgroundInput
             return null;
         }
         
-        int width = Top.Value?.Size.X ?? Bottom.Value.Size.X;
-        int height = Top.Value?.Size.Y ?? Bottom.Value.Size.Y;
+        int width = Math.Max(Top.Value?.Size.X ?? Bottom.Value.Size.X, Bottom.Value.Size.X);
+        int height = Math.Max(Top.Value?.Size.Y ?? Bottom.Value.Size.Y, Bottom.Value.Size.Y);
         
-        Texture workingSurface = new Texture(new VecI(width, height));
+        Texture workingSurface = RequestTexture(0, new VecI(width, height), true);
         
         if(Bottom.Value != null)
         {

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

@@ -109,7 +109,7 @@ public abstract class Node : IReadOnlyNode, IDisposable
         _keyFramesDirty = false;
     }
 
-    protected Texture RequestTexture(int id, VecI size, bool clear = false)
+    protected Texture RequestTexture(int id, VecI size, bool clear = true)
     {
         if (_managedTextures.TryGetValue(id, out var texture))
         {

+ 2 - 2
src/PixiEditor.DrawingApi.Skia/Implementations/SkiaPaintImplementation.cs

@@ -38,7 +38,7 @@ namespace PixiEditor.DrawingApi.Skia.Implementations
         {
             if (!ManagedInstances.TryGetValue(paintObjPointer, out var paint)) return;
 
-            if (paint.ColorFilter != null)
+            /*if (paint.ColorFilter != null)
             {
                 paint.ColorFilter.Dispose();
                 colorFilterImplementation.ManagedInstances.TryRemove(paint.ColorFilter.Handle, out _);
@@ -48,7 +48,7 @@ namespace PixiEditor.DrawingApi.Skia.Implementations
             {
                 paint.ImageFilter.Dispose();
                 imageFilterImplementation.ManagedInstances.TryRemove(paint.ImageFilter.Handle, out _);
-            }
+            }*/
             
             if (paint.Shader != null)
             {

+ 1 - 1
src/PixiEditor/ViewModels/ViewModelMain.cs

@@ -292,8 +292,8 @@ internal partial class ViewModelMain : ViewModelBase, ICommandsHandler
             // So they remain alive and keep "showing" the now disposed DocumentViewModel
             // And since they reference the DocumentViewModel it doesn't get collected by GC
 
-            document.Dispose();
             WindowSubViewModel.CloseViewportsForDocument(document);
+            document.Dispose();
 
             return true;
         }