From 8f578150eaf494a03bed7389046e44f2bdf7d748 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Thu, 22 Aug 2019 15:40:10 +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 data block 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 data block, by adding a new runtime field to bNodeTree. --- source/blender/editors/animation/drivers.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'source/blender/editors/animation/drivers.c') diff --git a/source/blender/editors/animation/drivers.c b/source/blender/editors/animation/drivers.c index e341a16378c..bf2056a7ec6 100644 --- a/source/blender/editors/animation/drivers.c +++ b/source/blender/editors/animation/drivers.c @@ -846,6 +846,36 @@ bool ANIM_driver_vars_paste(ReportList *reports, FCurve *fcu, bool replace) /* -------------------------------------------------- */ +/** Compute an ID pointer and path to property valid for use in a driver. + * Corrects for ID references that are not independent (e.g. material NodeTree). */ +bool ANIM_get_target_ID_and_path_to_property( + PointerRNA *ptr, PropertyRNA *prop, int index, ID **r_id, char **r_path) +{ + int dim = RNA_property_array_dimension(ptr, prop, NULL); + char *path = RNA_path_from_ID_to_property_index(ptr, prop, dim, index); + ID *id = ptr->id.data; + + if (!path) { + return false; + } + + if (GS(id->name) == ID_NT) { + bNodeTree *node_tree = (bNodeTree *)id; + + if (node_tree->owner) { + id = node_tree->owner; + + char *new_path = BLI_sprintfN("node_tree%s%s", path[0] == '[' ? "" : ".", path); + MEM_freeN(path); + path = new_path; + } + } + + *r_id = id; + *r_path = path; + return true; +} + /* Create a driver & variable that reads the specified property, * and store it in the buffers for Paste Driver and Paste Variables. */ void ANIM_copy_as_driver(struct ID *target_id, const char *target_path, const char *var_name) -- cgit v1.2.3