Fix T93231: crash when overwriting vertex group with other domain
The problem was that we forgot to actually remove the vertex group when it should be deleted. We only removed all the data that was attached to it. Differential Revision: https://developer.blender.org/D13326
This commit is contained in:
parent
0479a66313
commit
dab04bc053
Notes:
blender-bot
2023-02-13 17:05:01 +01:00
Referenced by issue #93231, geometry nodes, crash when attribute domain set to 'edge' when outputting to vertex weights
|
@ -50,6 +50,10 @@ void BKE_object_defgroup_active_index_set(struct Object *ob, const int new_index
|
|||
const struct ListBase *BKE_id_defgroup_list_get(const struct ID *id);
|
||||
struct ListBase *BKE_id_defgroup_list_get_mutable(struct ID *id);
|
||||
int BKE_id_defgroup_name_index(const struct ID *id, const char *name);
|
||||
bool BKE_id_defgroup_name_find(const struct ID *id,
|
||||
const char *name,
|
||||
int *r_index,
|
||||
struct bDeformGroup **r_group);
|
||||
|
||||
struct bDeformGroup *BKE_object_defgroup_new(struct Object *ob, const char *name);
|
||||
void BKE_defgroup_copy_list(struct ListBase *outbase, const struct ListBase *inbase);
|
||||
|
|
|
@ -557,11 +557,35 @@ bDeformGroup *BKE_object_defgroup_find_name(const Object *ob, const char *name)
|
|||
|
||||
int BKE_id_defgroup_name_index(const ID *id, const char *name)
|
||||
{
|
||||
if (name == NULL || name[0] == '\0') {
|
||||
int index;
|
||||
if (!BKE_id_defgroup_name_find(id, name, &index, NULL)) {
|
||||
return -1;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
bool BKE_id_defgroup_name_find(const struct ID *id,
|
||||
const char *name,
|
||||
int *r_index,
|
||||
struct bDeformGroup **r_group)
|
||||
{
|
||||
if (name == NULL || name[0] == '\0') {
|
||||
return false;
|
||||
}
|
||||
const ListBase *defbase = BKE_id_defgroup_list_get(id);
|
||||
return BLI_findstringindex(defbase, name, offsetof(bDeformGroup, name));
|
||||
int index;
|
||||
LISTBASE_FOREACH_INDEX (bDeformGroup *, group, defbase, index) {
|
||||
if (STREQ(name, group->name)) {
|
||||
if (r_index != NULL) {
|
||||
*r_index = index;
|
||||
}
|
||||
if (r_group != NULL) {
|
||||
*r_group = group;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const ListBase *BKE_object_defgroup_list(const Object *ob)
|
||||
|
|
|
@ -1134,16 +1134,19 @@ class VertexGroupsAttributeProvider final : public DynamicAttributesProvider {
|
|||
}
|
||||
|
||||
const std::string name = attribute_id.name();
|
||||
const int vertex_group_index = BLI_findstringindex(
|
||||
&mesh->vertex_group_names, name.c_str(), offsetof(bDeformGroup, name));
|
||||
if (vertex_group_index < 0) {
|
||||
|
||||
int index;
|
||||
bDeformGroup *group;
|
||||
if (!BKE_id_defgroup_name_find(&mesh->id, name.c_str(), &index, &group)) {
|
||||
return false;
|
||||
}
|
||||
BLI_remlink(&mesh->vertex_group_names, group);
|
||||
MEM_freeN(group);
|
||||
if (mesh->dvert == nullptr) {
|
||||
return true;
|
||||
}
|
||||
for (MDeformVert &dvert : MutableSpan(mesh->dvert, mesh->totvert)) {
|
||||
MDeformWeight *weight = BKE_defvert_find_index(&dvert, vertex_group_index);
|
||||
MDeformWeight *weight = BKE_defvert_find_index(&dvert, index);
|
||||
BKE_defvert_remove_group(&dvert, weight);
|
||||
}
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue