red-owl-games / Sleipnir

A Graph Framework for Unity
43 stars 5 forks source link

StartNode add-delete-add issue #3

Open AncientPixel opened 2 years ago

AncientPixel commented 2 years ago

Hi guys, I love this graph implementation and I'm currently using it in a small side project. Saying that, I have found a bug. 😄 When I add a Start node to a new graph, and then delete it and then try to add it again I get the following error:

ArgumentException: An item with the same key has already been added. Key: On Start System.Collections.Generic.Dictionary[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <bd21fd595d394493a51e7c79b5fef9e0>:0) System.Collections.Generic.Dictionary[TKey,TValue].Add (TKey key, TValue value) (at <bd21fd595d394493a51e7c79b5fef9e0>:0) RedOwl.Sleipnir.Engine.Node.DefineFlowPorts () (at Assets/Scripts/Engine/Node/Node.cs:127) RedOwl.Sleipnir.Engine.Node.Definition (RedOwl.Sleipnir.Engine.IGraph graph) (at Assets/Scripts/Engine/Node/Node.cs:94) RedOwl.Sleipnir.Engine.Graph.Add[T] (T node) (at Assets/Scripts/Engine/Graph/Graph.cs:128) RedOwl.Sleipnir.Editor.SleipnirGraphViewBase.CreateNode (RedOwl.Sleipnir.Engine.NodeAttribute data, UnityEngine.Vector2 position) (at Assets/Scripts/Editor/SleipnirGraphViewBase.cs:51)

[EDIT]: Ok I've found that if you stay on the graph window, and not reload the SerializedObject graph, this error happens. If you reload the graph this error wil not happen when adding a new Start node.

AncientPixel commented 2 years ago

Ok a workaround is to call Reload() at the end of the OnGraphViewChanged() function in SleipnirGraphViewEditmode.cs I could also just look for the offending Graph Port on the graph...