Browse Source

Fixed loops

flabbet 1 year ago
parent
commit
d685b5c8a1

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

@@ -45,6 +45,7 @@ public class NodeGraph : IReadOnlyNodeGraph, IDisposable
         while (queueNodes.Count > 0)
         {
             var node = queueNodes.Dequeue();
+            
             if (finalQueue.Contains(node))
             {
                 continue;

+ 19 - 0
src/PixiEditor.ChangeableDocument/Changes/NodeGraph/ConnectProperties_Change.cs

@@ -41,6 +41,11 @@ internal class ConnectProperties_Change : Change
         {
             return false;
         }
+        
+        if(IsLoop(inputProp, outputProp))
+        {
+            return false;
+        }
 
         bool canConnect = CheckTypeCompatibility(inputProp, outputProp);
 
@@ -53,6 +58,20 @@ internal class ConnectProperties_Change : Change
 
         return true;
     }
+    
+    private bool IsLoop(InputProperty input, OutputProperty output)
+    {
+        if (input.Node == output.Node)
+        {
+            return true;
+        }
+        if(input.Node.OutputProperties.Any(x => x.Connections.Any(y => y.Node == output.Node)))
+        {
+            return true;
+        }
+
+        return false;
+    }
 
     public override OneOf<None, IChangeInfo, List<IChangeInfo>> Apply(Document target, bool firstApply,
         out bool ignoreInUndo)