Versioning: fix vertex group name loss in linked duplicates.

After rB3b6ee8cee708 by @HooglyBoogly vertex groups were moved
to mesh data, and versioning code was provided to upgrade old
files. However, it fails to consider the case of linked duplicates
having different name lists, and dependent on the object order
can cause some of the names to be lost. This can even be all of
them, if there is a duplicate without any names, which can be
easily created by lazy Python code.

To fix this, change the code to use the longest available name list.

Differential Revision: https://developer.blender.org/D11958
This commit is contained in:
Alexander Gavrilov 2021-07-18 11:47:59 +03:00
parent 9eafdb985d
commit fc32567cda
1 changed files with 9 additions and 3 deletions

View File

@ -99,9 +99,15 @@ static void move_vertex_group_names_to_object_data(Main *bmain)
if (ELEM(object->type, OB_MESH, OB_LATTICE, OB_GPENCIL)) {
ListBase *new_defbase = BKE_object_defgroup_list_mutable(object);
/* Clear the list in case the it was already assigned from another object. */
BLI_freelistN(new_defbase);
*new_defbase = object->defbase;
/* Choose the longest vertex group name list among all linked duplicates. */
if (BLI_listbase_count(&object->defbase) < BLI_listbase_count(new_defbase)) {
BLI_freelistN(&object->defbase);
}
else {
/* Clear the list in case the it was already assigned from another object. */
BLI_freelistN(new_defbase);
*new_defbase = object->defbase;
}
}
}
}