Fix #132075: Realize instances crash with vertex group inputs

Caused by 84c7684871.

Previously we could count on adding the attributes to the result mesh
not failing. Now, since the vertex group names are copied, they might
fail because a name would cause the attribute to already exist with a
float type on the point domain, which might not match the most
complex domain/type we'd use otherwise.

The fix is to only create attributes as vertex groups if the domain and
type combination from all the input meshes is correct.

Pull Request: https://projects.blender.org/blender/blender/pulls/132506
This commit is contained in:
Hans Goudey
2024-12-31 22:16:29 +01:00
committed by Hans Goudey
parent 11e97bd593
commit 6bfb6399ea

View File

@@ -1524,7 +1524,9 @@ static void execute_realize_mesh_task(const RealizeInstancesOptions &options,
dst_attribute_writers);
}
static void copy_vertex_group_names(Mesh &dst_mesh, const Span<const Mesh *> src_meshes)
static void copy_vertex_group_names(Mesh &dst_mesh,
const OrderedAttributes &ordered_attributes,
const Span<const Mesh *> src_meshes)
{
Set<StringRef> existing_names;
LISTBASE_FOREACH (const bDeformGroup *, defgroup, &dst_mesh.vertex_group_names) {
@@ -1533,6 +1535,12 @@ static void copy_vertex_group_names(Mesh &dst_mesh, const Span<const Mesh *> src
for (const Mesh *mesh : src_meshes) {
LISTBASE_FOREACH (const bDeformGroup *, src, &mesh->vertex_group_names) {
const StringRef src_name = src->name;
const int attribute_index = ordered_attributes.ids.index_of(src_name);
const bke::AttributeDomainAndType kind = ordered_attributes.kinds[attribute_index];
if (kind.domain != bke::AttrDomain::Point || kind.data_type != CD_PROP_FLOAT) {
/* Prefer using the highest priority domain and type from all input meshes. */
continue;
}
if (existing_names.contains(src_name)) {
continue;
}
@@ -1590,7 +1598,8 @@ static void execute_realize_mesh_tasks(const RealizeInstancesOptions &options,
BLI_assert(BLI_listbase_count(&dst_mesh->vertex_group_names) ==
BLI_listbase_count(&first_mesh.vertex_group_names));
copy_vertex_group_names(*dst_mesh, all_meshes_info.order.as_span().drop_front(1));
copy_vertex_group_names(
*dst_mesh, ordered_attributes, all_meshes_info.order.as_span().drop_front(1));
dst_mesh->vertex_group_active_index = first_mesh.vertex_group_active_index;
/* Add materials. */