Fix: Deleting vertex group attribute can change original mesh

There was an error with the attribute API implementation for vertex
groups. If the vertex group layer referenced an original mesh, it wasn't
properly duplicated for writing.
This commit is contained in:
Hans Goudey 2022-03-11 11:25:59 -06:00
parent 28434dab0c
commit 5c86f0369c
1 changed files with 5 additions and 0 deletions

View File

@ -1049,6 +1049,11 @@ class VertexGroupsAttributeProvider final : public DynamicAttributesProvider {
if (mesh->dvert == nullptr) {
return true;
}
/* Copy the data layer if it is shared with some other mesh. */
mesh->dvert = (MDeformVert *)CustomData_duplicate_referenced_layer(
&mesh->vdata, CD_MDEFORMVERT, mesh->totvert);
for (MDeformVert &dvert : MutableSpan(mesh->dvert, mesh->totvert)) {
MDeformWeight *weight = BKE_defvert_find_index(&dvert, index);
BKE_defvert_remove_group(&dvert, weight);