From 34ed58dcaffd957f50380f4115d2cb9c46de31ee Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Thu, 22 Aug 2019 20:43:19 +0300 Subject: Fix T68971: Copy As New Driver from Material node creates a bad reference. NodeTree structures of materials and some other data blocks are effectively node group datablock objects that are contained inside the parent block. Thus, direct references to them are only valid while blender is running, and are lost on save. Fix Copy As New Driver to create a reference that goes through the owner datablock, by adding a new ID flag to mark private pseudo-datablocks. Also fix functions that return full paths to structures and properties, e.g. used in python tooltips. Functions for paths from ID to struct or property can't be changed because of Animation Data related code. Reviewers: mont29 Differential Revision: https://developer.blender.org/D5559 --- source/blender/blenkernel/intern/library.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source/blender/blenkernel/intern/library.c') diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 2dbca3b4db1..7c9f5c0ae77 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -1417,6 +1417,9 @@ void BKE_libblock_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int fla const bool use_nodetree_alloc_exception = ((GS(id->name) == ID_NT) && (bmain != NULL) && (BLI_findindex(&bmain->nodetrees, id) < 0)); + /* The id->flag bits to copy over. */ + const int copy_flag_mask = LIB_PRIVATE_DATA; + BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) != 0 || bmain != NULL); BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) != 0 || (flag & LIB_ID_CREATE_NO_ALLOCATE) == 0); BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) == 0 || (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) != 0); @@ -1448,6 +1451,8 @@ void BKE_libblock_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int fla memcpy(cpn + id_offset, cp + id_offset, id_len - id_offset); } + new_id->flag = (new_id->flag & ~copy_flag_mask) | (id->flag & copy_flag_mask); + if (id->properties) { new_id->properties = IDP_CopyProperty_ex(id->properties, flag); } -- cgit v1.2.3