Datablock ID Properties attached to bpy.types.Material are not saved (or loaded) #53509

Closed
opened 2017-12-08 12:07:13 +01:00 by Simon Wendsche · 10 comments

Short description of error

Attach a PointerProperty D113 to a material, let it point to an object, save and load the scene -> it will point to None.
E.g. the following code:

bpy.types.Material.testprop = bpy.props.PointerProperty(name="Attached to Material", type=bpy.types.Object)

To reproduce:

  • Install the attached example addon addon_test.py
  • Open default scene
  • Select default cube
  • Open material tab and set both test properties Attached to Material and Attached to Object to point to an object (e.g. the camera) scrn_2017-12-08_11-53-45.png
  • Save
  • Close Blender and Re-open
  • Load the saved scene
  • -> Attached to Material will point to None, while Attached to Object still points to the camera scrn_2017-12-08_11-54-33.png

System Information
Ubuntu 14.04

Blender Version
Broken: Official 2.79, latest master (4a73432)

**Short description of error** Attach a PointerProperty [D113](https://archive.blender.org/developer/D113) to a material, let it point to an object, save and load the scene -> it will point to None. E.g. the following code: ``` bpy.types.Material.testprop = bpy.props.PointerProperty(name="Attached to Material", type=bpy.types.Object) ``` To reproduce: * Install the attached example addon [addon_test.py](https://archive.blender.org/developer/F1342922/addon_test.py) * Open default scene * Select default cube * Open material tab and set both test properties **Attached to Material** and **Attached to Object** to point to an object (e.g. the camera) ![scrn_2017-12-08_11-53-45.png](https://archive.blender.org/developer/F1342894/scrn_2017-12-08_11-53-45.png) * Save * Close Blender and Re-open * Load the saved scene * -> **Attached to Material** will point to None, while **Attached to Object** still points to the camera ![scrn_2017-12-08_11-54-33.png](https://archive.blender.org/developer/F1342898/scrn_2017-12-08_11-54-33.png) **System Information** Ubuntu 14.04 **Blender Version** Broken: Official 2.79, latest master (4a73432)
Author

Added subscriber: @BYOB

Added subscriber: @BYOB
Author

I just discovered that it also unlinks when undoing something in object mode.

I just discovered that it also unlinks when undoing something in object mode.

Added subscribers: @mont29, @Sergey

Added subscribers: @mont29, @Sergey
Bastien Montagne was assigned by Sergey Sharybin 2017-12-18 14:20:16 +01:00

Pointer properties is something what Cycles is using, so not sure why those would fail (those are not ID pointers though).

@mont29, is that something related on ID custom pointers?

Pointer properties is something what Cycles is using, so not sure why those would fail (those are not ID pointers though). @mont29, is that something related on ID custom pointers?
Author

They are Datablock ID Properties (see D113), exposed in Python since 2.79.

They are Datablock ID Properties (see [D113](https://archive.blender.org/developer/D113)), exposed in Python since 2.79.
Author

I hope I don't get on your nerves when I say that it would be good to have a fix for this bug in 2.79a.
It is crippling any external renderer addon that uses Datablock ID Properties.

I hope I don't get on your nerves when I say that it would be good to have a fix for this bug in 2.79a. It is crippling any external renderer addon that uses Datablock ID Properties.
Author

I might have a fix for this.
In the function lib_link_material in the file source/blender/blenloader/intern/readfile.c, the statement IDP_LibLinkProperty(ma->id.properties, fd); is executed twice:

			IDP_LibLinkProperty(ma->id.properties, fd);
			lib_link_animdata(fd, &ma->id, ma->adt);
			
			/* Link ID Properties -- and copy this comment EXACTLY for easy finding
			 * of library blocks that implement this.*/
			IDP_LibLinkProperty(ma->id.properties, fd);

I commented out the second call to IDP_LibLinkProperty and now my demo addon works as expected (both PointerProperties survive a save and load).

This is the patch:

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index f43eecf..75615b2 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -3968,7 +3968,7 @@ static void lib_link_material(FileData *fd, Main *main)
                        
                        /* Link ID Properties -- and copy this comment EXACTLY for easy finding
                         * of library blocks that implement this.*/
-                       IDP_LibLinkProperty(ma->id.properties, fd);
+                       // IDP_LibLinkProperty(ma->id.properties, fd);
                        
                        ma->ipo = newlibadr_us(fd, ma->id.lib, ma->ipo);  // XXX deprecated - old animation system
                        ma->group = newlibadr_us(fd, ma->id.lib, ma->group);

Please have a look at it and tell me if it's complete bogus, if we need to fix something else or if this is indeed the only thing necessary to fix the bug.

I might have a fix for this. In the function **lib_link_material** in the file **source/blender/blenloader/intern/readfile.c**, the statement **IDP_LibLinkProperty(ma->id.properties, fd);** is executed twice: ``` IDP_LibLinkProperty(ma->id.properties, fd); lib_link_animdata(fd, &ma->id, ma->adt); /* Link ID Properties -- and copy this comment EXACTLY for easy finding * of library blocks that implement this.*/ IDP_LibLinkProperty(ma->id.properties, fd); ``` I commented out the second call to **IDP_LibLinkProperty** and now my demo addon works as expected (both PointerProperties survive a save and load). This is the patch: ``` diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index f43eecf..75615b2 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -3968,7 +3968,7 @@ static void lib_link_material(FileData *fd, Main *main) /* Link ID Properties -- and copy this comment EXACTLY for easy finding * of library blocks that implement this.*/ - IDP_LibLinkProperty(ma->id.properties, fd); + // IDP_LibLinkProperty(ma->id.properties, fd); ma->ipo = newlibadr_us(fd, ma->id.lib, ma->ipo); // XXX deprecated - old animation system ma->group = newlibadr_us(fd, ma->id.lib, ma->group); ``` Please have a look at it and tell me if it's complete bogus, if we need to fix something else or if this is indeed the only thing necessary to fix the bug.

Nice catch, this is indeed plain bold stupid bug! Thanks for the investigation.

Nice catch, this is indeed plain bold stupid bug! Thanks for the investigation.

This issue was referenced by 96e507d989

This issue was referenced by 96e507d9890e42695ea0c6bff0c8fa5c480bbb5a

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
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
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#53509
No description provided.