From cd0a4ca64bde87cf2aac1c25368545068c7b7b34 Mon Sep 17 00:00:00 2001 From: Thor Brigsted Date: Thu, 19 Jul 2018 00:01:11 +0200 Subject: [PATCH] Fixed bug in NodeEditorGUILayout.InstancePortList --- Scripts/Editor/NodeEditorGUILayout.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Scripts/Editor/NodeEditorGUILayout.cs b/Scripts/Editor/NodeEditorGUILayout.cs index 1192561..3003e1a 100644 --- a/Scripts/Editor/NodeEditorGUILayout.cs +++ b/Scripts/Editor/NodeEditorGUILayout.cs @@ -195,6 +195,15 @@ namespace XNodeEditor { if (hasArrayData) { arrayData.DeleteArrayElementAtIndex(i); arraySize--; + // Error handling. If the following happens too often, file a bug report at https://github.com/Siccity/xNode/issues + if (instancePorts.Count <= arraySize) { + while (instancePorts.Count <= arraySize) { + arrayData.DeleteArrayElementAtIndex(--arraySize); + } + Debug.LogWarning("Array size exceeded instance ports size. Excess items removed."); + } + serializedObject.ApplyModifiedProperties(); + serializedObject.Update(); } i--; } else { @@ -220,10 +229,11 @@ namespace XNodeEditor { int i = 0; while (node.HasPort(newName)) newName = fieldName + " " + (++i); - instancePorts.Add(node.AddInstanceOutput(type, connectionType, newName)); + node.AddInstanceOutput(type, connectionType, newName); serializedObject.Update(); EditorUtility.SetDirty(node); if (hasArrayData) arrayData.InsertArrayElementAtIndex(arraySize); + serializedObject.ApplyModifiedProperties(); } GUILayout.EndHorizontal(); }