From 772d1d0e3b0c9853a38e3bbd0a3eff78f37d162f Mon Sep 17 00:00:00 2001 From: Leon Schittek Date: Tue, 14 Mar 2023 23:41:07 +0100 Subject: [PATCH] Fix #105778: Prevent invalid links with link swap Don't allow links between outputs and inputs of the same node when swapping links. These invalid links are now removed. --- .../editors/space_node/node_relationships.cc | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/source/blender/editors/space_node/node_relationships.cc b/source/blender/editors/space_node/node_relationships.cc index 6cd0705a402..6b8c6df9ca5 100644 --- a/source/blender/editors/space_node/node_relationships.cc +++ b/source/blender/editors/space_node/node_relationships.cc @@ -958,18 +958,31 @@ static void node_swap_links(bNodeLinkDrag &nldrag, bNodeTree &ntree) if (linked_socket.is_input()) { LISTBASE_FOREACH (bNodeLink *, link, &ntree.links) { - if (link->tosock == &linked_socket) { - link->tosock = start_socket; - link->tonode = start_node; + if (link->tosock != &linked_socket) { + continue; } + if (link->fromnode == start_node) { + /* Don't link a node to itself. */ + nodeRemLink(&ntree, link); + continue; + } + + link->tosock = start_socket; + link->tonode = start_node; } } else { LISTBASE_FOREACH (bNodeLink *, link, &ntree.links) { - if (link->fromsock == &linked_socket) { - link->fromsock = start_socket; - link->fromnode = start_node; + if (link->fromsock != &linked_socket) { + continue; } + if (link->tonode == start_node) { + /* Don't link a node to itself. */ + nodeRemLink(&ntree, link); + continue; + } + link->fromsock = start_socket; + link->fromnode = start_node; } } -- 2.30.2