Browse Source

Hopefully fixed some access violation issues

flabbet 10 months ago
parent
commit
0c30deafc6

+ 0 - 1
src/ChunkyImageLib/ChunkyImageLib.csproj

@@ -4,7 +4,6 @@
     <TargetFramework>net8.0</TargetFramework>
     <TargetFramework>net8.0</TargetFramework>
     <ImplicitUsings>enable</ImplicitUsings>
     <ImplicitUsings>enable</ImplicitUsings>
     <Nullable>enable</Nullable>
     <Nullable>enable</Nullable>
-    <WarningsAsErrors>Nullable</WarningsAsErrors>
     <AllowUnsafeBlocks>True</AllowUnsafeBlocks>
     <AllowUnsafeBlocks>True</AllowUnsafeBlocks>
   </PropertyGroup>
   </PropertyGroup>
   
   

+ 13 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/CreateImageNode.cs

@@ -18,6 +18,8 @@ public class CreateImageNode : Node
     public InputProperty<Color> Fill { get; }
     public InputProperty<Color> Fill { get; }
 
 
     public RenderInputProperty Content { get; }
     public RenderInputProperty Content { get; }
+    
+    public RenderOutputProperty RenderOutput { get; }
 
 
     public CreateImageNode()
     public CreateImageNode()
     {
     {
@@ -25,6 +27,7 @@ public class CreateImageNode : Node
         Size = CreateInput(nameof(Size), "SIZE", new VecI(32, 32)).WithRules(v => v.Min(VecI.One));
         Size = CreateInput(nameof(Size), "SIZE", new VecI(32, 32)).WithRules(v => v.Min(VecI.One));
         Fill = CreateInput(nameof(Fill), "FILL", Colors.Transparent);
         Fill = CreateInput(nameof(Fill), "FILL", Colors.Transparent);
         Content = CreateRenderInput(nameof(Content), "CONTENT");
         Content = CreateRenderInput(nameof(Content), "CONTENT");
+        RenderOutput = CreateRenderOutput("RenderOutput", "RENDER_OUTPUT", () => new Painter(OnPaint));
     }
     }
 
 
     protected override void OnExecute(RenderContext context)
     protected override void OnExecute(RenderContext context)
@@ -37,10 +40,20 @@ public class CreateImageNode : Node
         var surface = RequestTexture(0, Size.Value, false);
         var surface = RequestTexture(0, Size.Value, false);
 
 
         surface.DrawingSurface.Canvas.Clear(Fill.Value);
         surface.DrawingSurface.Canvas.Clear(Fill.Value);
+        
+        int saved = surface.DrawingSurface.Canvas.Save();
 
 
         Content.Value?.Paint(context, surface.DrawingSurface);
         Content.Value?.Paint(context, surface.DrawingSurface);
 
 
+        surface.DrawingSurface.Canvas.RestoreToCount(saved);
         Output.Value = surface;
         Output.Value = surface;
+        
+        RenderOutput.ChainToPainterValue();
+    }
+    
+    private void OnPaint(RenderContext context, DrawingSurface surface)
+    {
+        surface.Canvas.DrawSurface(Output.Value.DrawingSurface, 0, 0);
     }
     }
 
 
     public override Node CreateCopy() => new CreateImageNode();
     public override Node CreateCopy() => new CreateImageNode();

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

@@ -51,8 +51,11 @@ public class OutputNode : Node, IRenderInput, IPreviewRenderable
         }
         }
         
         
         RenderContext context = new(renderOn, frame, resolution, VecI.One);
         RenderContext context = new(renderOn, frame, resolution, VecI.One);
+        int saved = renderOn.Canvas.Save();
         Input.Value.Paint(context, renderOn);
         Input.Value.Paint(context, renderOn);
         
         
+        renderOn.Canvas.RestoreToCount(saved);
+        
         return true;
         return true;
     }
     }
 }
 }

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

@@ -190,6 +190,8 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
             renderSurface = new Texture(targetSize);
             renderSurface = new Texture(targetSize);
         }
         }
 
 
+        renderSurface.DrawingSurface.Canvas.Save();
+        
         if (!img.DrawMostUpToDateChunkOn(
         if (!img.DrawMostUpToDateChunkOn(
                 chunkPos,
                 chunkPos,
                 ChunkResolution.Full,
                 ChunkResolution.Full,
@@ -202,6 +204,8 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
                 clearPaint);
                 clearPaint);
         }
         }
         
         
+        renderSurface.DrawingSurface.Canvas.Restore();
+        
         renderSurface?.DrawingSurface.Flush(true, true);
         renderSurface?.DrawingSurface.Flush(true, true);
     }
     }
 
 

+ 3 - 3
src/PixiEditor/Models/DocumentModels/ActionAccumulator.cs

@@ -90,8 +90,8 @@ internal class ActionAccumulator
             List<IChangeInfo> optimizedChanges = ChangeInfoListOptimizer.Optimize(changes);
             List<IChangeInfo> optimizedChanges = ChangeInfoListOptimizer.Optimize(changes);
             bool undoBoundaryPassed =
             bool undoBoundaryPassed =
                 toExecute.Any(static action => action.action is ChangeBoundary_Action or Redo_Action or Undo_Action);
                 toExecute.Any(static action => action.action is ChangeBoundary_Action or Redo_Action or Undo_Action);
-            /*bool viewportRefreshRequest =
-                toExecute.Any(static action => action.action is RefreshViewport_PassthroughAction);*/
+            bool viewportRefreshRequest =
+                toExecute.Any(static action => action.action is RefreshViewport_PassthroughAction);
             foreach (IChangeInfo info in optimizedChanges)
             foreach (IChangeInfo info in optimizedChanges)
             {
             {
                 internals.Updater.ApplyChangeFromChangeInfo(info);
                 internals.Updater.ApplyChangeFromChangeInfo(info);
@@ -106,7 +106,7 @@ internal class ActionAccumulator
             if (DrawingBackendApi.Current.IsHardwareAccelerated)
             if (DrawingBackendApi.Current.IsHardwareAccelerated)
             {
             {
                 canvasUpdater.UpdateGatheredChunksSync(affectedAreas,
                 canvasUpdater.UpdateGatheredChunksSync(affectedAreas,
-                    undoBoundaryPassed);
+                    undoBoundaryPassed || viewportRefreshRequest);
             }
             }
             else
             else
             {
             {