Fix #120103: Copy/Paste of nodes is not handling ID references properly. #121122

Merged
Bastien Montagne merged 9 commits from mont29/blender:tmp-node-copypaste into main 2024-04-28 18:59:52 +02:00

This commit fixes several critical issues with previous code:

  • It only covered a (very small) subset of potential ID references in a
    node (namely, just the bNode::id pointer).
  • It completely ignored linked data case.
  • It would modify ID pointers in the clipboard itself.

The new code stores ID reference info in a separate mapping. It uses the
new 'sub-data' foreach_id feature from BKE_lib_query to reliably and
generically process all ID pointers of a node.

The paste handling of ID pointers is split in two steps:

  • All knowns ID references are searched for in current Main data-base,
    and the result (current valid ID pointer or null if not found) is
    stored temporarily in the ID references mapping.
  • Once a node has been duplicated from the clipboard into the paste
    destination nodetree, its ID pointers are updated accordingly.

This allows to keep the 'reference ID' data in the clipboard always
valid, regardless of which IDs are currently existing in Main (i.e. to
keep all available data, even when opening new blendfiles, or doing
undo/redo that would affect the existing IDs).

This commit fixes several critical issues with previous code: * It only covered a (very small) subset of potential ID references in a node (namely, just the `bNode::id` pointer). * It completely ignored linked data case. * It would modify ID pointers in the clipboard itself. The new code stores ID reference info in a separate mapping. It uses the new 'sub-data' foreach_id feature from `BKE_lib_query` to reliably and generically process all ID pointers of a node. The paste handling of ID pointers is split in two steps: * All knowns ID references are searched for in current Main data-base, and the result (current valid ID pointer or null if not found) is stored temporarily in the ID references mapping. * Once a node has been duplicated from the clipboard into the paste destination nodetree, its ID pointers are updated accordingly. This allows to keep the 'reference ID' data in the clipboard always valid, regardless of which IDs are currently existing in Main (i.e. to keep all available data, even when opening new blendfiles, or doing undo/redo that would affect the existing IDs).
Bastien Montagne added 2 commits 2024-04-26 12:48:26 +02:00
9daceb581c WIP: BKE_lib_query: Add a partial ID usage iterator system.
The idea is to allow iterating over e.g. all ID usages of a node from a
whole nodetree, using the same generic handling as existing 'whole ID'
`foreach_id` code.

This is necessary in some cases wher a sub-data needs to processed
independently from any 'owner ID', e.g. in some copy/paste handling.

This is a pre-requirement for proper fix of nodes copy/paste (see
e.g. #120103).
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
dab19d2a63
Fix #102103: Copy/Paste of nodes is not handling ID references properly.
This commit fixes several critical issues with previous code:
* It only covered a (very small) subset of potential ID references in a
  node (namely, just the `bNode::id` pointer).
* It completely ignored linked data case.
* It would modify ID pointers in the clipboard itself.

The new code stores ID reference info in a separate mapping. It uses the
new 'sub-data' foreach_id feature from `BKE_lib_query` to reliably and
generically process all ID pointers of a node.

The paste handling of ID pointers is split in two steps:
* All knowns ID references are searched for in current Main data-base,
  and the result (current valid ID pointer or null if not found) is
  stored temporarily in the ID references mapping.
* Once a node has been duplicated from the clipboard into the paste
  destination nodetree, its ID pointers are updated accordingly.

This allows to keep the 'reference ID' data in the clipboard always
valid, regardless of which IDs are currently existing in Main (i.e. to
keep all available data, even when opening new blendfiles, or doing
undo/redo that would affect the existing IDs).
Author
Owner

NOTE: Depends on (and contains) !121018

NOTE: Depends on (and contains) !121018
Author
Owner

@blender-bot build

@blender-bot build
Bastien Montagne added a new dependency 2024-04-26 12:50:31 +02:00
Bastien Montagne removed a dependency 2024-04-26 12:50:36 +02:00
Bastien Montagne force-pushed tmp-node-copypaste from dab19d2a63 to d64274bb08 2024-04-26 12:52:52 +02:00 Compare
Bastien Montagne changed title from Fix #102103: Copy/Paste of nodes is not handling ID references properly. to Fix #120103: Copy/Paste of nodes is not handling ID references properly. 2024-04-26 12:53:05 +02:00
Author
Owner

@blender-bot build

@blender-bot build
Bastien Montagne requested review from Philipp Oeser 2024-04-26 13:04:29 +02:00
Bastien Montagne requested review from Jacques Lucke 2024-04-26 13:04:30 +02:00
Philipp Oeser approved these changes 2024-04-26 13:33:28 +02:00
Philipp Oeser left a comment
Member

Functionality works fine from the tests I previously had with #120103.

For the code-side: I wont dive into this due to time-constraints

Functionality works fine from the tests I previously had with #120103. For the code-side: I wont dive into this due to time-constraints
Bastien Montagne force-pushed tmp-node-copypaste from d64274bb08 to 420948d966 2024-04-26 14:28:11 +02:00 Compare
Jacques Lucke approved these changes 2024-04-26 19:27:24 +02:00
Jacques Lucke left a comment
Member

Only found one major issue which I reported in #121018. Otherwise LGTM.

Only found one major issue which I reported in #121018. Otherwise LGTM.
@ -26,2 +28,4 @@
namespace blender::ed::space_node {
struct NodeClipboardItemIDInfo {
/* Name and library filepath form a unique identifer for a given ID. */
Member

Comment style: /**. Same in a few places below.

Comment style: `/**`. Same in a few places below.
mont29 marked this conversation as resolved
@ -27,1 +29,4 @@
struct NodeClipboardItemIDInfo {
/* Name and library filepath form a unique identifer for a given ID. */
std::string id_name = "";
Member

It's not really necessary to write these initializers for std::string and std::optional. They are always default-constructed anyway.

It's not really necessary to write these initializers for `std::string` and `std::optional`. They are always default-constructed anyway.
Author
Owner

I know, but I find it cleaner/more readable to be explicit about default values...

I know, but I find it cleaner/more readable to be explicit about default values...
mont29 marked this conversation as resolved
@ -28,0 +30,4 @@
struct NodeClipboardItemIDInfo {
/* Name and library filepath form a unique identifer for a given ID. */
std::string id_name = "";
/* Note: Library reference is stored as an absolute path. Since the Node clippboard is runtime
Member

typo (clippboard)

typo (`clippboard`)
mont29 marked this conversation as resolved
@ -58,0 +81,4 @@
*
* DO NOT update the nodes' pointers here though, as this would affect the clipboard content,
* which is no desired here. It should remain as in original state, such that e.g. one can copy
* nodes in file `A.blend`, open file `B.blend`, paste nodes (and lose some of the invlaid ID
Member

typo (invalid)

typo (`invalid`)
mont29 marked this conversation as resolved
@ -83,0 +111,4 @@
* and libpath pairs can be used here.
* - UID cannot be trusted accross file load.
* - ID pointer itself cannot be trusted accross undo/redo and fileload. */
auto validate_id_fn = [this, &is_valid, &bmain, &bmain_id_map, &libraries_path_to_id](
Member

It's ok to just use & if the lambda does not leave the current scope.

It's ok to just use `&` if the lambda does not leave the current scope.
Author
Owner

Here as well, I find explicit capturing of required variables cleaner and more readable tbh

Here as well, I find explicit capturing of required variables cleaner and more readable tbh
mont29 marked this conversation as resolved
Bastien Montagne added 4 commits 2024-04-28 14:07:24 +02:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
ae30d3c359
Fix from review.
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
aca9de6f84
Fixes from review.
Author
Owner

@blender-bot build

@blender-bot build
Bastien Montagne added 1 commit 2024-04-28 18:19:19 +02:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
b795a2ef67
Merge branch 'main' into tmp-node-copypaste
Author
Owner

@blender-bot build

@blender-bot build
Bastien Montagne merged commit e5a921ad9b into main 2024-04-28 18:59:52 +02:00
Bastien Montagne deleted branch tmp-node-copypaste 2024-04-28 18:59:54 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#121122
No description provided.