Page MenuHome

Datablock ID Properties attached to bpy.types.Material are not saved (or loaded)
Closed, ResolvedPublic


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
  • 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)
  • 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

System Information
Ubuntu 14.04

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

Event Timeline

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

Sergey Sharybin (sergey) lowered the priority of this task from 90 to Normal.

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

@Bastien Montagne (mont29), is that something related on ID custom pointers?

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

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 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->, fd); is executed twice:

			IDP_LibLinkProperty(ma->, 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->, 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->, fd);
+                       // IDP_LibLinkProperty(ma->, 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.

Bastien Montagne (mont29) triaged this task as 50 priority.Jan 8 2018, 9:25 AM

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