Fix T103301: Active and default color attributes lost in many operations

When creating a new mesh to change it in some way, the active and
default color attribute names should be copied to the new mesh.
Doing that in the generic "copy parameters for eval" function should
cover the vast majority of cases.
This commit is contained in:
Hans Goudey 2022-12-19 14:56:39 -06:00
parent 4ae0da1bbc
commit c2a8d8b18d
Notes: blender-bot 2023-02-14 10:37:50 +01:00
Referenced by issue #103301, Crash with Blender Studio's stretching visualization file
2 changed files with 13 additions and 9 deletions

View File

@ -979,6 +979,18 @@ Mesh *BKE_mesh_new_nomain(
return mesh;
}
static void copy_attribute_names(const Mesh &mesh_src, Mesh &mesh_dst)
{
if (mesh_src.active_color_attribute) {
MEM_SAFE_FREE(mesh_dst.active_color_attribute);
mesh_dst.active_color_attribute = BLI_strdup(mesh_src.active_color_attribute);
}
if (mesh_src.default_color_attribute) {
MEM_SAFE_FREE(mesh_dst.default_color_attribute);
mesh_dst.default_color_attribute = BLI_strdup(mesh_src.default_color_attribute);
}
}
void BKE_mesh_copy_parameters(Mesh *me_dst, const Mesh *me_src)
{
/* Copy general settings. */
@ -1008,6 +1020,7 @@ void BKE_mesh_copy_parameters_for_eval(Mesh *me_dst, const Mesh *me_src)
BLI_assert(me_dst->id.tag & (LIB_TAG_NO_MAIN | LIB_TAG_COPIED_ON_WRITE));
BKE_mesh_copy_parameters(me_dst, me_src);
copy_attribute_names(*me_src, *me_dst);
/* Copy vertex group names. */
BLI_assert(BLI_listbase_is_empty(&me_dst->vertex_group_names));

View File

@ -1125,15 +1125,6 @@ static void execute_realize_mesh_tasks(const RealizeInstancesOptions &options,
}
});
if (first_mesh.active_color_attribute) {
MEM_SAFE_FREE(dst_mesh->active_color_attribute);
dst_mesh->active_color_attribute = BLI_strdup(first_mesh.active_color_attribute);
}
if (first_mesh.default_color_attribute) {
MEM_SAFE_FREE(dst_mesh->default_color_attribute);
dst_mesh->default_color_attribute = BLI_strdup(first_mesh.default_color_attribute);
}
/* Tag modified attributes. */
for (GSpanAttributeWriter &dst_attribute : dst_attribute_writers) {
dst_attribute.finish();