LibOverride: Add ID pointer to operations over ID pointers. #110773

Merged
Bastien Montagne merged 1 commits from mont29/blender:liboverride-unique-id-items-library into main 2023-08-10 12:41:27 +02:00

In RNA collections storing ID references, the name of the collection
item may not always be unique, when several IDs from different libraries
are present.

While rare, this situation can become deadly to liboverride, by causing
random but exponential liboverride hierarchies corruptions.

This has already been alleviated by using preferably both name and index
in items lookup (a05419f18b) and by reducing the risk of name collision
in general between liboverrides and their linked reference (b9becc47de).

This commit goes further, by ensuring that references to items of RNA
collections of IDs stored in liboverride operations become completely
unambiguous. This is achieved by storing an extra pointer to the item's
ID itself, when relevant.

Lookup then requires a complete match name + ID to be successful,
which is guaranteed to match at most a single item in the whole RNA
collection (since RNA collection of IDs do not allow duplicates, and
the ID pointer is always unique).

Note that this ID pointer is implemented as an std::optional one
(either directly in C++ code, or using an new liboverride operation flag
in DNA). This allows to smoothly transition from existing data to the
added ID pointer info (when needed), without needing any dedicated
versioning. This solution also preserves forward compatibility as much
as possible.

It may also provide marginal performances improvements in some cases, as
looking up for ID items in RNA collections will first check for the
ID pointer, which should be faster than a string comparison.

Implements #110421.


NOTE: Initial patch was storing the Library pointer of the ID, however this cannot work when linking a liboverride, since Library data is always local and never linked between blendfiles. So instead this patch directly stores a 'weak reference' to the ID pointer of the RNA collection items.

In RNA collections storing ID references, the name of the collection item may not always be unique, when several IDs from different libraries are present. While rare, this situation can become deadly to liboverride, by causing random but exponential liboverride hierarchies corruptions. This has already been alleviated by using preferably both name and index in items lookup (a05419f18b) and by reducing the risk of name collision in general between liboverrides and their linked reference (b9becc47de). This commit goes further, by ensuring that references to items of RNA collections of IDs stored in liboverride operations become completely unambiguous. This is achieved by storing an extra pointer to the item's ID itself, when relevant. Lookup then requires a complete match `name + ID` to be successful, which is guaranteed to match at most a single item in the whole RNA collection (since RNA collection of IDs do not allow duplicates, and the ID pointer is always unique). Note that this ID pointer is implemented as an `std::optional` one (either directly in C++ code, or using an new liboverride operation `flag` in DNA). This allows to smoothly transition from existing data to the added ID pointer info (when needed), without needing any dedicated versioning. This solution also preserves forward compatibility as much as possible. It may also provide marginal performances improvements in some cases, as looking up for ID items in RNA collections will first check for the ID pointer, which should be faster than a string comparison. Implements #110421. -------------------------- NOTE: Initial patch was storing the Library pointer of the ID, however this cannot work when linking a liboverride, since Library data is always local and never linked between blendfiles. So instead this patch directly stores a 'weak reference' to the ID pointer of the RNA collection items.
Author
Owner

@blender-bot package

@blender-bot package
Member

Package build started. Download here when ready.

Package build started. [Download here](https://builder.blender.org/download/patch/PR110773) when ready.
Hans Goudey reviewed 2023-08-04 00:10:44 +02:00
@ -356,2 +364,4 @@
const char *subitem_refname,
const char *subitem_locname,
const std::optional<struct Library *> subitem_reflib,
const std::optional<struct Library *> subitem_loclib,
Member

struct is unnecessary even for forward declared types in C++

`struct` is unnecessary even for forward declared types in C++
mont29 marked this conversation as resolved
@ -3755,0 +3767,4 @@
IDOverrideLibraryPropertyOperation *opop;
for (opop = static_cast<IDOverrideLibraryPropertyOperation *>(BLI_findstring_ptr(
liboverride_operations, subitem_main_name, int(offesetof_opop_main_name)));
opop;
Member

Looks like this line does nothing

Looks like this line does nothing
Author
Owner

It's the condition check of the for loop... We do not want to keep looping and processing over null opop pointer.

It's the condition check of the `for` loop... We do not want to keep looping and processing over null `opop` pointer.
Member

Oh, of course, sorry-- didn't realize the for loop was spread over so many lines!

Oh, of course, sorry-- didn't realize the for loop was spread over so many lines!
mont29 marked this conversation as resolved
Bastien Montagne force-pushed liboverride-unique-id-items-library from b7290c4da5 to 1b0c7d73ff 2023-08-04 11:39:54 +02:00 Compare
Bastien Montagne force-pushed liboverride-unique-id-items-library from 1b0c7d73ff to 503116471b 2023-08-07 12:12:27 +02:00 Compare
Bastien Montagne force-pushed liboverride-unique-id-items-library from 503116471b to 073a352554 2023-08-07 14:29:24 +02:00 Compare
Bastien Montagne changed title from WIP: LibOverride: Add library pointer to operations over ID pointers. to LibOverride: Add ID pointer to operations over ID pointers. 2023-08-07 14:31:50 +02:00
Author
Owner

@blender-bot build

@blender-bot build
Bastien Montagne force-pushed liboverride-unique-id-items-library from 073a352554 to f00c427955 2023-08-07 14:39:38 +02:00 Compare
Author
Owner

@brecht not sure if you want to check on this one? It implements the idea we were discussing about regarding making liboverride reference to RNA collection IDs items fully non-ambiguous.

@brecht not sure if you want to check on this one? It implements the idea we were discussing about regarding making liboverride reference to RNA collection IDs items fully non-ambiguous.
Author
Owner

@blender-bot build

@blender-bot build
Author
Owner

@blender-bot build

@blender-bot build
Author
Owner

@blender-bot build

@blender-bot build
Brecht Van Lommel approved these changes 2023-08-08 15:17:17 +02:00
Brecht Van Lommel left a comment
Owner

I can't say I understand the overrides system well enough to fully understand the consequences of this, but it seems to match what we discussed.

I can't say I understand the overrides system well enough to fully understand the consequences of this, but it seems to match what we discussed.
Bastien Montagne merged commit 6a86dd5f34 into main 2023-08-10 12:41:27 +02:00
Bastien Montagne deleted branch liboverride-unique-id-items-library 2023-08-10 12:41:29 +02:00
Sign in to join this conversation.
No reviewers
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
4 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#110773
No description provided.