From dab04bc0536feb37140d7644ba5bc6ba8588699c Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Tue, 23 Nov 2021 14:35:49 +0100 Subject: 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 --- source/blender/blenkernel/BKE_deform.h | 4 ++++ source/blender/blenkernel/intern/deform.c | 28 ++++++++++++++++++++-- .../blenkernel/intern/geometry_component_mesh.cc | 11 +++++---- 3 files changed, 37 insertions(+), 6 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/BKE_deform.h b/source/blender/blenkernel/BKE_deform.h index f4221d57428..cca99f9d1cd 100644 --- a/source/blender/blenkernel/BKE_deform.h +++ b/source/blender/blenkernel/BKE_deform.h @@ -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); diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c index 13222747a52..a2f285dab51 100644 --- a/source/blender/blenkernel/intern/deform.c +++ b/source/blender/blenkernel/intern/deform.c @@ -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) diff --git a/source/blender/blenkernel/intern/geometry_component_mesh.cc b/source/blender/blenkernel/intern/geometry_component_mesh.cc index c3e39c0b2cb..0456316151c 100644 --- a/source/blender/blenkernel/intern/geometry_component_mesh.cc +++ b/source/blender/blenkernel/intern/geometry_component_mesh.cc @@ -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; -- cgit v1.2.3 From 436ce221941403dd8a3f9ec3740d22f70f4c2ad8 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Tue, 23 Nov 2021 14:37:10 +0100 Subject: Fix T93296: raycast node uses wrong domain for face corner attributes This changes what domain is used by the raycast mode. This should fix the behavior for face corner attributes (but may make it a bit slower for other attributes). I think for 3.0 this is an acceptable trade off. For 3.1 we can do what the comment suggests already. Differential Revision: https://developer.blender.org/D13333 --- source/blender/nodes/geometry/nodes/node_geo_raycast.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source/blender') diff --git a/source/blender/nodes/geometry/nodes/node_geo_raycast.cc b/source/blender/nodes/geometry/nodes/node_geo_raycast.cc index 34946b1115c..42924a46667 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_raycast.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_raycast.cc @@ -205,10 +205,10 @@ class RaycastFunction : public fn::MultiFunction { std::unique_ptr target_evaluator_; const GVArray *target_data_ = nullptr; - /* Always evaluate the target domain data on the point domain. Eventually this could be - * exposed as an option or determined automatically from the field inputs in order to avoid - * losing information if the target field is on a different domain. */ - const AttributeDomain domain_ = ATTR_DOMAIN_POINT; + /* Always evaluate the target domain data on the face corner domain because it contains the most + * information. Eventually this could be exposed as an option or determined automatically from + * the field inputs for better performance. */ + const AttributeDomain domain_ = ATTR_DOMAIN_CORNER; fn::MFSignature signature_; -- cgit v1.2.3