1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-20 01:06:01 +08:00

Improved null handling

This commit is contained in:
Thor Kramer Brigsted 2017-10-30 11:38:36 +01:00
parent b9e06be096
commit eaeca48f69
2 changed files with 5 additions and 4 deletions

View File

@ -116,7 +116,7 @@ public partial class NodeEditorWindow {
public void DrawConnections() {
foreach (Node node in graph.nodes) {
//If a null node is found, return. This can happen if the nodes associated script is deleted. It is currently not possible in Unity to delete a null asset.
if (node == null) return;
if (node == null) continue;
for (int i = 0; i < node.OutputCount; i++) {
NodePort output = node.outputs[i];
@ -126,8 +126,9 @@ public partial class NodeEditorWindow {
for (int k = 0; k < output.ConnectionCount; k++) {
NodePort input = output.GetConnection(k);
if (input == null) return; //If a script has been updated and the port doesn't exist, it is removed and null is returned. If this happens, return.
if (!_portConnectionPoints.ContainsKey(input)) return;
if (input == null) continue; //If a script has been updated and the port doesn't exist, it is removed and null is returned. If this happens, return.
if (!input.IsConnectedTo(output)) input.Connect(output);
if (!_portConnectionPoints.ContainsKey(input)) continue;
Vector2 to = _portConnectionPoints[input].center;
DrawConnection(from, to, NodeEditorPreferences.GetTypeColor(output.type));
}

View File

@ -145,7 +145,7 @@ public class NodePort {
if (direction == port.direction) { Debug.LogWarning("Cannot connect two " + (direction == IO.Input ? "input" : "output") + " connections"); return; }
connections.Add(new PortConnection(port));
if (port.connections == null) port.connections = new List<PortConnection>();
port.connections.Add(new PortConnection(this));
if (!port.IsConnectedTo(this)) port.connections.Add(new PortConnection(this));
node.OnCreateConnection(this, port);
port.node.OnCreateConnection(this, port);
}