Fix T104089: Removing greasepencil vertex group can leave no active

We should always have an active vertexgroup (making sure this is the
case was just not happening on the greasepencil side).

Now do this (similar to what is done for other object types in
`object_defgroup_remove_common`).

Maniphest Tasks: T104089

Differential Revision: https://developer.blender.org/D17091
This commit is contained in:
Philipp Oeser 2023-01-23 13:50:34 +01:00
parent ef3225b9da
commit 12ca26afc2
Notes: blender-bot 2023-02-14 06:27:47 +01:00
Referenced by issue #100749, Blender LTS: Maintenance Task 3.3
Referenced by issue #104089, Removing greasepencil vertexgroups can leave no active
1 changed files with 12 additions and 0 deletions

View File

@ -1861,6 +1861,18 @@ void BKE_gpencil_vgroup_remove(Object *ob, bDeformGroup *defgroup)
/* Remove the group */
BLI_freelinkN(&gpd->vertex_group_names, defgroup);
/* Update the active deform index if necessary. */
const int active_index = BKE_object_defgroup_active_index_get(ob);
if (active_index > def_nr) {
BKE_object_defgroup_active_index_set(ob, active_index - 1);
}
/* Keep a valid active index if we still have some vertex groups. */
if (!BLI_listbase_is_empty(&gpd->vertex_group_names) &&
BKE_object_defgroup_active_index_get(ob) < 1) {
BKE_object_defgroup_active_index_set(ob, 1);
}
DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
}