From 4b21067aea415f7eb4604de6dd133a67a4063640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 17 Dec 2021 17:31:15 +0100 Subject: Fix T94116: Drivers can have multiple variables with same name The RNA setter now ensures that driver variables are uniquely named (within the scope of the driver). Versioning code has been added to ensure this uniqueness. The last variable with the non-unique name retains the original name; this ensures that the driver will still evaluate to the same value as before this fix. This also introduces a new blenlib function `BLI_listbase_from_link()`, which can be used to find the entire list from any item within the list. Manifest Task: T94116 Reviewed By: mont29, JacquesLucke Maniphest Tasks: T94116 Differential Revision: https://developer.blender.org/D13594 --- source/blender/blenloader/intern/versioning_300.c | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c index 7a7f12a7e58..6b22d2f97e9 100644 --- a/source/blender/blenloader/intern/versioning_300.c +++ b/source/blender/blenloader/intern/versioning_300.c @@ -30,6 +30,7 @@ #include "BLI_math_vector.h" #include "BLI_path_util.h" #include "BLI_string.h" +#include "BLI_string_utils.h" #include "BLI_utildefines.h" #include "DNA_anim_types.h" @@ -790,6 +791,32 @@ void do_versions_after_linking_300(Main *bmain, ReportList *UNUSED(reports)) */ { /* Keep this block, even when empty. */ + + { /* Ensure driver variable names are unique within the driver. */ + ID *id; + FOREACH_MAIN_ID_BEGIN (bmain, id) { + AnimData *adt = BKE_animdata_from_id(id); + if (adt == NULL) { + continue; + } + LISTBASE_FOREACH (FCurve *, fcu, &adt->drivers) { + ChannelDriver *driver = fcu->driver; + /* Ensure the uniqueness front to back. Given a list of identically + * named variables, the last one gets to keep its original name. This + * matches the evaluation order, and thus shouldn't change the evaluated + * value of the driver expression. */ + LISTBASE_FOREACH (DriverVar *, dvar, &driver->variables) { + BLI_uniquename(&driver->variables, + dvar, + dvar->name, + '_', + offsetof(DriverVar, name), + sizeof(dvar->name)); + } + } + } + FOREACH_MAIN_ID_END; + } } } -- cgit v1.2.3