Fix #111963: Copying sockets was not creating unique identifiers
Items in the node group interface need to have unique identifiers. Copying an item (socket or panel) was not doing this, so the node groups end up having sockets with the same identifier. Linking sockets was broken because copies could not be distinguished. Pull Request: https://projects.blender.org/blender/blender/pulls/111972
This commit is contained in:
@@ -408,6 +408,23 @@ static void item_copy(bNodeTreeInterfaceItem &dst,
|
||||
}
|
||||
}
|
||||
|
||||
static void item_set_unique_identifier(const int uid, bNodeTreeInterfaceItem &item)
|
||||
{
|
||||
switch (item.item_type) {
|
||||
case NODE_INTERFACE_SOCKET: {
|
||||
bNodeTreeInterfaceSocket &socket = reinterpret_cast<bNodeTreeInterfaceSocket &>(item);
|
||||
MEM_SAFE_FREE(socket.identifier);
|
||||
socket.identifier = BLI_sprintfN("Socket_%d", uid);
|
||||
break;
|
||||
}
|
||||
case NODE_INTERFACE_PANEL: {
|
||||
bNodeTreeInterfacePanel &panel = reinterpret_cast<bNodeTreeInterfacePanel &>(item);
|
||||
panel.identifier = uid;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void item_free(bNodeTreeInterfaceItem &item, const bool do_id_user)
|
||||
{
|
||||
switch (item.item_type) {
|
||||
@@ -1172,6 +1189,7 @@ bNodeTreeInterfaceItem *bNodeTreeInterface::add_item_copy(const bNodeTreeInterfa
|
||||
|
||||
bNodeTreeInterfaceItem *citem = static_cast<bNodeTreeInterfaceItem *>(MEM_dupallocN(&item));
|
||||
item_types::item_copy(*citem, item, 0);
|
||||
item_types::item_set_unique_identifier(next_uid++, *citem);
|
||||
parent->add_item(*citem);
|
||||
|
||||
return citem;
|
||||
@@ -1196,6 +1214,7 @@ bNodeTreeInterfaceItem *bNodeTreeInterface::insert_item_copy(const bNodeTreeInte
|
||||
|
||||
bNodeTreeInterfaceItem *citem = static_cast<bNodeTreeInterfaceItem *>(MEM_dupallocN(&item));
|
||||
item_types::item_copy(*citem, item, 0);
|
||||
item_types::item_set_unique_identifier(next_uid++, *citem);
|
||||
parent->insert_item(*citem, position);
|
||||
|
||||
return citem;
|
||||
|
||||
@@ -159,7 +159,10 @@ typedef struct bNodeTreeInterfacePanel {
|
||||
*/
|
||||
bNodeTreeInterfacePanel *find_parent_recursive(const bNodeTreeInterfaceItem &item);
|
||||
|
||||
/** Create a copy of items in the span and add them to the interface. */
|
||||
/**
|
||||
* Create a copy of items in the span and add them to the interface.
|
||||
* \note This does not generate new identifiers for items, use only for identital copies.
|
||||
*/
|
||||
void copy_from(blender::Span<const bNodeTreeInterfaceItem *> items_src, int flag);
|
||||
/** Remove all items from the panel. */
|
||||
void clear(bool do_id_user);
|
||||
|
||||
Reference in New Issue
Block a user