Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWannes Malfait <Wannes>2021-07-28 16:43:24 +0300
committerJacques Lucke <jacques@blender.org>2021-07-28 16:43:24 +0300
commit31fcb934a4c13563cec9afd41c5a88d50fc845d1 (patch)
treea2e43cd4e01ff3dda5af83621227ceff1b396d12
parentf9308a585ecdd1d9e287caa8e0643347784c17e2 (diff)
Fix T89415: update multi input indices after deleting a node
When deleting a node, links attached to that node are deleted, but if one of those links was connected to a multi input socket, the indices of the other links connected to it were not updated. This adds updates both in the case of a normal delete as well as after a delete with reconnect. Differential Revision: https://developer.blender.org/D11716
-rw-r--r--source/blender/blenkernel/intern/node.cc29
1 files changed, 29 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index e9608457896..9888e23a7bd 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -2504,6 +2504,22 @@ bool nodeLinkIsHidden(const bNodeLink *link)
return nodeSocketIsHidden(link->fromsock) || nodeSocketIsHidden(link->tosock);
}
+/* Adjust the indices of links connected to the given multi input socket after deleting the link at
+ * `deleted_index`. This function also works if the link has not yet been deleted. */
+static void adjust_multi_input_indices_after_removed_link(bNodeTree *ntree,
+ bNodeSocket *sock,
+ int deleted_index)
+{
+ LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) {
+ /* We only need to adjust those with a greater index, because the others will have the same
+ * index. */
+ if (link->tosock != sock || link->multi_input_socket_index <= deleted_index) {
+ continue;
+ }
+ link->multi_input_socket_index -= 1;
+ }
+}
+
void nodeInternalRelink(bNodeTree *ntree, bNode *node)
{
/* store link pointers in output sockets, for efficient lookup */
@@ -2537,10 +2553,18 @@ void nodeInternalRelink(bNodeTree *ntree, bNode *node)
ntree->update |= NTREE_UPDATE_LINKS;
}
else {
+ if (link->tosock->flag & SOCK_MULTI_INPUT) {
+ adjust_multi_input_indices_after_removed_link(
+ ntree, link->tosock, link->multi_input_socket_index);
+ }
nodeRemLink(ntree, link);
}
}
else {
+ if (link->tosock->flag & SOCK_MULTI_INPUT) {
+ adjust_multi_input_indices_after_removed_link(
+ ntree, link->tosock, link->multi_input_socket_index);
+ };
nodeRemLink(ntree, link);
}
}
@@ -2991,6 +3015,11 @@ void nodeUnlinkNode(bNodeTree *ntree, bNode *node)
}
if (lb) {
+ /* Only bother adjusting if the socket is not on the node we're deleting. */
+ if (link->tonode != node && link->tosock->flag & SOCK_MULTI_INPUT) {
+ adjust_multi_input_indices_after_removed_link(
+ ntree, link->tosock, link->multi_input_socket_index);
+ }
LISTBASE_FOREACH (bNodeSocket *, sock, lb) {
if (link->fromsock == sock || link->tosock == sock) {
nodeRemLink(ntree, link);