Gentlymad-Studios / NewGraph

A general node graph solution centered on data management. This is based on the idea to visualize complex data structures as graph networks without having to modify already established data classes.
MIT License
231 stars 16 forks source link

Deleting graph while graph window is open throws errors #49

Open Appleguysnake opened 6 months ago

Appleguysnake commented 6 months ago

Pretty obvious what went wrong when this happens, but errors are thrown every update so it seems like it should be handled in some way.

Repro

Result: this error is thrown until the window is closed

SerializedObject target has been destroyed.
UnityEngine.StackTraceUtility:ExtractStackTrace ()
NewGraph.NodeModel:SetPosition (single,single) (at Assets/NewGraph/Models/NodeModel.cs:174)
NewGraph.NodeController:SetPosition (single,single) (at Assets/NewGraph/Editor/Controllers/NodeController.cs:67)
NewGraph.NodeView:SetPosition (UnityEngine.Vector2) (at Assets/NewGraph/Editor/Views/NodeView.cs:313)
GraphViewBase.GraphElement:ApplyDeltaToPosition (UnityEngine.Vector2) (at ./Library/PackageCache/com.gentlymad.graphviewbase@9e7e3c3574/Editor/Elements/Graph/GraphElement.cs:128)
GraphViewBase.GraphElementContainer:HandleDrag (GraphViewBase.DragEvent,GraphViewBase.BaseNode) (at ./Library/PackageCache/com.gentlymad.graphviewbase@9e7e3c3574/Editor/Elements/GraphElementContainer.cs:208)
GraphViewBase.GraphElementContainer:OnDrag (GraphViewBase.DragEvent) (at ./Library/PackageCache/com.gentlymad.graphviewbase@9e7e3c3574/Editor/Elements/GraphElementContainer.cs:202)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

Expected result

I'm not sure what the preferred / simplest way to handle this would be. When deleting open scenes in Unity, the behavior is that the scene is marked dirty and you're asked if you want to save it whenever you close it or the editor. Just closing the graph window would make sense as well. Catching the error and throwing a message to tell the user to close the window also seems fine.

Appleguysnake commented 6 months ago

Bonus: If you delete the graph when it has corrupt graph data as in #50 the error is different:

ArgumentException: Object at index 0 is null
UnityEditor.SerializedObject..ctor (UnityEngine.Object obj) (at <80a8ce1980c648dca8e68f0d8aa3b930>:0)
NewGraph.GraphModelBase.CreateSerializedObject (UnityEngine.Object scope, System.String rootFieldName) (at Assets/NewGraph/Models/GraphModelBase.cs:147)
NewGraph.MonoGraphModel.CreateSerializedObject () (at Assets/NewGraph/Models/MonoGraphModel.cs:61)
NewGraph.MonoGraphModel.get_BaseObject () (at Assets/NewGraph/Models/MonoGraphModel.cs:44)
NewGraph.GraphSettings.SetLastOpenedGraphData (NewGraph.IGraphModelData graphData) (at Assets/NewGraph/Editor/Settings/GraphSettings.cs:36)
NewGraph.GraphController+<>c__DisplayClass43_0.<Load>b__0 () (at Assets/NewGraph/Editor/Controllers/GraphController.cs:452)
UnityEngine.UIElements.VisualElement+SimpleScheduledItem.PerformTimerUpdate (UnityEngine.UIElements.TimerState state) (at <332857d8803a4878904bcf8f9581ec33>:0)
UnityEngine.UIElements.TimerEventScheduler.UpdateScheduledEvents () (at <332857d8803a4878904bcf8f9581ec33>:0)
UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.UpdateSchedulers () (at <332857d8803a4878904bcf8f9581ec33>:0)
UnityEngine.UIElements.UIEventRegistration.UpdateSchedulers () (at <332857d8803a4878904bcf8f9581ec33>:0)
UnityEditor.RetainedMode.UpdateSchedulers () (at <cc76bab7efe9480f901125fd04a708b6>:0)