[Bf-blender-cvs] [3522532cb26] ui-asset-view-template: Fix T85966: Wrong link picked when dragging multi-input socket

Fabian Schempp noreply at git.blender.org
Wed Mar 3 21:45:18 CET 2021


Commit: 3522532cb26899341e125a1ff3fe27e5c6189da8
Author: Fabian Schempp
Date:   Tue Mar 2 23:09:38 2021 +0100
Branches: ui-asset-view-template
https://developer.blender.org/rB3522532cb26899341e125a1ff3fe27e5c6189da8

Fix T85966: Wrong link picked when dragging multi-input socket

The socket drag operator stored the index of the last picked socket
into RNA in case the mouse cursor leaves the link while dragging.

This id was not unique which is why sometimes a link from an other node
with the same id is picked.

This patch changes the way the last picked link is stored and stores a
pointer to the link directly into bNodeLinkDrag struct instead.

Differential Revision: https://developer.blender.org/D10590

===================================================================

M	source/blender/editors/space_node/node_intern.h
M	source/blender/editors/space_node/node_relationships.c

===================================================================

diff --git a/source/blender/editors/space_node/node_intern.h b/source/blender/editors/space_node/node_intern.h
index 972e6cab123..4ec8f56480e 100644
--- a/source/blender/editors/space_node/node_intern.h
+++ b/source/blender/editors/space_node/node_intern.h
@@ -59,6 +59,9 @@ typedef struct bNodeLinkDrag {
   ListBase links;
   bool from_multi_input_socket;
   int in_out;
+
+  /** Temporarily stores the last picked link from multi input socket operator. */
+  struct bNodeLink *last_picked_multi_input_socket_link;
 } bNodeLinkDrag;
 
 typedef struct SpaceNode_Runtime {
diff --git a/source/blender/editors/space_node/node_relationships.c b/source/blender/editors/space_node/node_relationships.c
index d6edfcce8e8..218102d2261 100644
--- a/source/blender/editors/space_node/node_relationships.c
+++ b/source/blender/editors/space_node/node_relationships.c
@@ -280,7 +280,7 @@ static void pick_input_link_by_link_intersect(const bContext *C,
         float distance = dist_squared_to_line_segment_v2(cursor, l1, l2);
         if (distance < cursor_link_touch_distance) {
           link_to_pick = link;
-          RNA_int_set(op->ptr, "last_picked_link_index", link->multi_input_socket_index);
+          nldrag->last_picked_multi_input_socket_link = link_to_pick;
         }
       }
     }
@@ -290,13 +290,9 @@ static void pick_input_link_by_link_intersect(const bContext *C,
    * Not essential for the basic behavior, but can make interaction feel a bit better if
    * the  mouse moves to the right and loses the "selection." */
   if (!link_to_pick) {
-    int last_picked_link_index = RNA_int_get(op->ptr, "last_picked_link_index");
-    if (last_picked_link_index > -1) {
-      LISTBASE_FOREACH (bNodeLink *, link, &snode->edittree->links) {
-        if (link->multi_input_socket_index == last_picked_link_index) {
-          link_to_pick = link;
-        }
-      }
+    bNodeLink *last_picked_link = nldrag->last_picked_multi_input_socket_link;
+    if (last_picked_link) {
+      link_to_pick = last_picked_link;
     }
   }
 
@@ -1032,13 +1028,14 @@ static int node_link_invoke(bContext *C, wmOperator *op, const wmEvent *event)
   float cursor[2];
   UI_view2d_region_to_view(&region->v2d, event->mval[0], event->mval[1], &cursor[0], &cursor[1]);
   RNA_float_set_array(op->ptr, "drag_start", cursor);
-  RNA_int_set(op->ptr, "last_picked_link_index", -1);
   RNA_boolean_set(op->ptr, "has_link_picked", false);
 
   ED_preview_kill_jobs(CTX_wm_manager(C), bmain);
 
   bNodeLinkDrag *nldrag = node_link_init(bmain, snode, cursor, detach);
 
+  nldrag->last_picked_multi_input_socket_link = NULL;
+
   if (nldrag) {
     op->customdata = nldrag;
     BLI_addtail(&snode->runtime->linkdrag, nldrag);
@@ -1102,15 +1099,6 @@ void NODE_OT_link(wmOperatorType *ot)
                       -UI_PRECISION_FLOAT_MAX,
                       UI_PRECISION_FLOAT_MAX);
   RNA_def_property_flag(prop, PROP_HIDDEN);
-  RNA_def_int(ot->srna,
-              "last_picked_link_index",
-              -1,
-              -1,
-              4095,
-              "Last Picked Link Index",
-              "The index of the last picked link on a multi-input socket",
-              -1,
-              4095);
   RNA_def_property_flag(prop, PROP_HIDDEN);
 }



More information about the Bf-blender-cvs mailing list