Cyanilux / ShaderGraphVariables

Adds 'Register Variable' and 'Get Variable' nodes to Shader Graph, allowing you to link sections of a graph without connection wires. <3
MIT License
255 stars 24 forks source link

`ArgumentNullException : Value cannot be null` error with a specific graph - unity 2022.3.14 #11

Open NeistH2o opened 4 months ago

NeistH2o commented 4 months ago

For some reason I can't explain, I get an exception when one of my graphs is open, I recently updated from v1.0.0 to v1.0.5 .

The problem with this error is that the graph becomes impossible to edit, as Unity throws NullReferenceExceptions when I try to move a node, create or delete one, or anything else.

I copied the exception I'm getting below but what is happening seems to be that an edge that links two node seems to have its node variable set to null, and unity fails to recover from there. At least that's what I understood, but I failed to prevent this from happening, and I don't know exactly what is the root cause, as other graphs seem to work without problem.

The only way I found to get back control over the graph was to add return null; at the very beginning of the Connect(Port a, Port b, bool noValidate = false) method in SGVariables.cs.

I can't share the shadergraph file here but let me know if you want me to send it to you in some other way.

Errors (collapsed) ```csharp ArgumentNullException: Value cannot be null. Parameter name: identifier UnityEditor.Undo.RegisterCompleteObjectUndo (UnityEngine.Object objectToUndo, System.String name) (at :0) UnityEditor.Graphing.GraphObject.RegisterCompleteObjectUndo (System.String actionName) (at ./Library/PackageCache/com.unity.shadergraph@14.0.9/Editor/Data/Implementation/GraphObject.cs:113) UnityEditor.ShaderGraph.Drawing.GraphEditorView.GraphViewChanged (UnityEditor.Experimental.GraphView.GraphViewChange graphViewChange) (at ./Library/PackageCache/com.unity.shadergraph@14.0.9/Editor/Drawing/Views/GraphEditorView.cs:488) UnityEditor.Experimental.GraphView.SelectionDragger.OnMouseUp (UnityEngine.UIElements.MouseUpEvent evt) (at <9bf8e89a4e1c457c8a246151ea3730b4>:0) UnityEngine.UIElements.EventCallbackFunctor`1[TEventType].Invoke (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.PropagationPhase propagationPhase) (at <545885fff981424ba24fbd84a445d137>:0) UnityEngine.UIElements.EventCallbackRegistry.InvokeCallbacks (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.PropagationPhase propagationPhase) (at <545885fff981424ba24fbd84a445d137>:0) UnityEngine.UIElements.CallbackEventHandler.HandleEvent (UnityEngine.UIElements.EventBase evt) (at <545885fff981424ba24fbd84a445d137>:0) UnityEngine.UIElements.CallbackEventHandler.HandleEventAtCurrentTargetAndPhase (UnityEngine.UIElements.EventBase evt) (at <545885fff981424ba24fbd84a445d137>:0) UnityEngine.UIElements.CallbackEventHandler.HandleEventAtTargetPhase (UnityEngine.UIElements.EventBase evt) (at <545885fff981424ba24fbd84a445d137>:0) UnityEngine.UIElements.MouseCaptureDispatchingStrategy.DispatchEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <545885fff981424ba24fbd84a445d137>:0) UnityEngine.UIElements.EventDispatcher.ApplyDispatchingStrategies (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, System.Boolean imguiEventIsInitiallyUsed) (at <545885fff981424ba24fbd84a445d137>:0) UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <545885fff981424ba24fbd84a445d137>:0) UnityEngine.UIElements.EventDispatcher.ProcessEventQueue () (at <545885fff981424ba24fbd84a445d137>:0) UnityEngine.UIElements.EventDispatcher.OpenGate () (at <545885fff981424ba24fbd84a445d137>:0) UnityEngine.UIElements.EventDispatcherGate.Dispose () (at <545885fff981424ba24fbd84a445d137>:0) UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <545885fff981424ba24fbd84a445d137>:0) UnityEngine.UIElements.EventDispatcher.Dispatch (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, UnityEngine.UIElements.DispatchMode dispatchMode) (at <545885fff981424ba24fbd84a445d137>:0) UnityEngine.UIElements.BaseVisualElementPanel.SendEvent (UnityEngine.UIElements.EventBase e, UnityEngine.UIElements.DispatchMode dispatchMode) (at <545885fff981424ba24fbd84a445d137>:0) UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at <545885fff981424ba24fbd84a445d137>:0) UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& eventHandled) (at <545885fff981424ba24fbd84a445d137>:0) UnityEngine.UIElements.UIEventRegistration.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <545885fff981424ba24fbd84a445d137>:0) UnityEngine.UIElements.UIEventRegistration+<>c.<.cctor>b__1_2 (System.Int32 i, System.IntPtr ptr) (at <545885fff981424ba24fbd84a445d137>:0) UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& result) (at :0) ``` and/or ```chsarp NullReferenceException: Object reference not set to an instance of an object UnityEditor.ShaderGraph.Drawing.GraphEditorView.HandleGraphChanges (System.Boolean wasUndoRedoPerformed) (at ./Library/PackageCache/com.unity.shadergraph@14.0.9/Editor/Drawing/Views/GraphEditorView.cs:814) UnityEditor.ShaderGraph.Drawing.MaterialGraphEditWindow.Update () (at ./Library/PackageCache/com.unity.shadergraph@14.0.9/Editor/Drawing/MaterialGraphEditWindow.cs:372) UnityEditor.EditorApplication:Internal_CallUpdateFunctions() ``` ```chsarp NullReferenceException: Object reference not set to an instance of an object UnityEditor.ShaderGraph.Drawing.GraphEditorView.HandleGraphChanges (System.Boolean wasUndoRedoPerformed) (at ./Library/PackageCache/com.unity.shadergraph@14.0.9/Editor/Drawing/Views/GraphEditorView.cs:814) UnityEditor.ShaderGraph.Drawing.MaterialGraphEditWindow.Update () (at ./Library/PackageCache/com.unity.shadergraph@14.0.9/Editor/Drawing/MaterialGraphEditWindow.cs:384) UnityEditor.HostView.SendUpdate () (at :0) UnityEditor.EditorApplication.Internal_CallUpdateFunctions () (at :0) ```
fleity commented 1 week ago

I can confirm that this issue exists. As far as I can tell it happens when the input of a register variable changes from vector4 to float or vice versa.

If you can figure out which node causes the problem in a graph, you can temporarily uninstall the package, delete the node, reinstall the package and the graph will work again (even if the rest still contains variables).