Browse Source

Fix: Node Tree Update only updates the sockets it found when starting update

Basically what this commit does, it prevents the update function from clearing any socket that can be reused - or should be reused because there was an error.
It also makes it so that sockets which aren't found but are declared by the interface
will be added, but there will be no attempt to run do_relink() on them.
Joseph Brandenburg 6 months ago
parent
commit
5930a984b4
1 changed files with 22 additions and 14 deletions
  1. 22 14
      base_definitions.py

+ 22 - 14
base_definitions.py

@@ -345,8 +345,6 @@ def node_group_update(node, force = False):
     #
     #
     if len(node.inputs) > 0 and (inp := node.inputs[-1]).bl_idname == 'WildcardSocket' and inp.is_linked:
     if len(node.inputs) > 0 and (inp := node.inputs[-1]).bl_idname == 'WildcardSocket' and inp.is_linked:
         update_input = True
         update_input = True
-    if len(node.outputs) > 0 and  (out := node.outputs[-1]).bl_idname == 'WildcardSocket' and out.is_linked:
-        update_output = True
     #
     #
     if not (update_input or update_output):
     if not (update_input or update_output):
         node.id_data.do_live_update = toggle_update
         node.id_data.do_live_update = toggle_update
@@ -371,15 +369,24 @@ def node_group_update(node, force = False):
                 if sl := node.inputs.get("Schema Length"):
                 if sl := node.inputs.get("Schema Length"):
                     schema_length = sl.default_value
                     schema_length = sl.default_value
                 # sometimes this isn't available yet # TODO not happy about this solution
                 # sometimes this isn't available yet # TODO not happy about this solution
+            remove_me=[]
+            # remove all found map items but the Schema Length input (reuse it)
+            for i, socket in enumerate(node.inputs):
+                if socket.identifier == "Schema Length" and i == 0:
+                    continue
+                elif socket.identifier in socket_map_in.keys():
+                    remove_me.append(socket)
+            while remove_me:
+                node.inputs.remove(remove_me.pop())
+            
+        if update_output:
+            remove_me=[]
+            for socket in node.outputs:
+                if socket.identifier in socket_map_out.keys():
+                    remove_me.append(socket)
+            while remove_me:
+                node.inputs.remove(remove_me.pop())
 
 
-            if node.bl_idname == 'MantisSchemaGroup':
-                while (len(node.inputs) > 1):
-                    node.inputs.remove(node.inputs[-1])
-                    # remove all but the Schema Length input (reuse it)
-            else: # for a regular node group it's OK to clear
-                node.inputs.clear()
-
-        if update_output: node.outputs.clear()
 
 
         from .utilities import relink_socket_map_add_socket
         from .utilities import relink_socket_map_add_socket
 
 
@@ -388,14 +395,15 @@ def node_group_update(node, force = False):
             if (item.in_out == 'INPUT' and update_input):
             if (item.in_out == 'INPUT' and update_input):
                 socket = relink_socket_map_add_socket(node, node.inputs, item)
                 socket = relink_socket_map_add_socket(node, node.inputs, item)
                 if socket_map_in:
                 if socket_map_in:
-                    do_relink(node, socket, socket_map_in)
+                    if item.identifier in socket_map_in.keys():
+                        do_relink(node, socket, socket_map_in)
 
 
             if (item.in_out == 'OUTPUT' and update_output):
             if (item.in_out == 'OUTPUT' and update_output):
                 socket = relink_socket_map_add_socket(node, node.outputs, item)
                 socket = relink_socket_map_add_socket(node, node.outputs, item)
                 if socket_map_out:
                 if socket_map_out:
-                    do_relink(node, socket, socket_map_out)
-
-        
+                    if item.identifier in socket_map_out.keys():
+                        do_relink(node, socket, socket_map_out)
+                    
         # at this point there is no wildcard socket
         # at this point there is no wildcard socket
         if socket_map_in and '__extend__' in socket_map_in.keys():
         if socket_map_in and '__extend__' in socket_map_in.keys():
             do_relink(node, None, socket_map_in, in_out='INPUT', parent_name='Constant' )
             do_relink(node, None, socket_map_in, in_out='INPUT', parent_name='Constant' )