Fix #135438: Prevent vertex group name collision when renaming bones.

When renaming bones, vertex groups that has the same name as the old
name of the bone will be renamed to the new name, but this may cause
name collision in the vertex group list. When this happens, we should
not change the vertex group's name. Now a warning message will show.

Pull Request: https://projects.blender.org/blender/blender/pulls/135492
This commit is contained in:
YimingWu
2025-03-07 12:52:09 +01:00
committed by YimingWu
parent 8ebeafa6b9
commit 308e81fd8a
@@ -255,8 +255,19 @@ void ED_armature_bone_rename(Main *bmain,
}
if (BKE_modifiers_uses_armature(ob, arm) && BKE_object_supports_vertex_groups(ob)) {
bDeformGroup *dg = BKE_object_defgroup_find_name(ob, oldname);
if (dg) {
if (bDeformGroup *existing_dg = BKE_object_defgroup_find_name(ob, newname)) {
WM_reportf(
eReportType::RPT_WARNING,
"%s (%s::%s)",
RPT_("New bone name collides with an existing vertex group name, vertex group "
"names are unchanged."),
&ob->id.name[2],
newname);
/* Not renaming vertex group could cause bone to bind to other vertex group, in this case
* deformation could change, so we tag this object for depsgraph update. */
DEG_id_tag_update(static_cast<ID *>(ob->data), ID_RECALC_GEOMETRY);
}
else if (bDeformGroup *dg = BKE_object_defgroup_find_name(ob, oldname)) {
STRNCPY(dg->name, newname);
if (ob->type == OB_GREASE_PENCIL) {