From e17ada3fcada32cb634e941e2683781d7ad22970 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 16 Jun 2018 21:29:10 -0400 Subject: [PATCH] Fix access violation in node socket updates As it turns out, enumerating a collection that can be modified is a bad idea. Indeed, Blender expects that we won't do this. Sometimes, it appears to work, however, other times, Blender is unable to handle it and the internal data gets corrupted, causing a crash. --- korman/nodes/node_core.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/korman/nodes/node_core.py b/korman/nodes/node_core.py index 4d1bb8f..1bfdcca 100644 --- a/korman/nodes/node_core.py +++ b/korman/nodes/node_core.py @@ -170,7 +170,13 @@ class PlasmaNodeBase: input_defs, output_defs = self._socket_defs for defs, sockets in ((input_defs, self.inputs), (output_defs, self.outputs)): done = set() - for i, socket in enumerate(sockets): + + # Need to enumerate by hand because blendsucks has major (crashing) issues if we modify + # this swhizzle while stuff is going down. + i = 0 + while i < len(sockets): + socket = sockets[i] + options = defs.get(socket.alias, None) if options is None or socket.bl_idname != options["type"]: sockets.remove(socket) @@ -227,6 +233,8 @@ class PlasmaNodeBase: sockets.remove(empty_sockets.pop()) done.add(socket.alias) + i += 1 + # Create any new sockets for alias in (j for j in defs if j not in done): options = defs[alias]