Fix: CustomData layers become unsorted in versioning

n versioning, when converting CD_SCULPT_FACE_SETS to CD_PROP_INT32
the layers were not kept properly ordered by type.

This was discovered while investigating T104053

Differential Revision: D17165
This commit is contained in:
Martijn Versteegh 2023-02-01 12:13:20 +01:00
parent e1ee86b63c
commit d92edca862
Notes: blender-bot 2023-02-14 08:59:10 +01:00
Referenced by commit d77b87eb93, Fix invalid versioning code for meshes
Referenced by issue #104299, Crash when opening file (customData)
1 changed files with 18 additions and 7 deletions

View File

@ -1228,12 +1228,18 @@ void BKE_mesh_legacy_face_set_from_generic(Mesh *mesh,
blender::MutableSpan<CustomDataLayer> poly_layers)
{
using namespace blender;
void *faceset_data = nullptr;
for (CustomDataLayer &layer : poly_layers) {
if (StringRef(layer.name) == ".sculpt_face_set") {
layer.type = CD_SCULPT_FACE_SETS;
faceset_data = layer.data;
layer.data = nullptr;
CustomData_free_layer_named(&mesh->pdata, ".sculpt_face_set", mesh->totpoly);
break;
}
}
CustomData_update_typemap(&mesh->pdata);
if (faceset_data != nullptr) {
CustomData_add_layer(&mesh->pdata, CD_SCULPT_FACE_SETS, CD_ASSIGN, faceset_data, mesh->totpoly);
}
}
void BKE_mesh_legacy_face_set_to_generic(Mesh *mesh)
@ -1242,13 +1248,18 @@ void BKE_mesh_legacy_face_set_to_generic(Mesh *mesh)
if (mesh->attributes().contains(".sculpt_face_set")) {
return;
}
for (CustomDataLayer &layer : MutableSpan(mesh->pdata.layers, mesh->pdata.totlayer)) {
if (layer.type == CD_SCULPT_FACE_SETS) {
BLI_strncpy(layer.name, ".sculpt_face_set", sizeof(layer.name));
layer.type = CD_PROP_INT32;
void *faceset_data = nullptr;
for (const int i : IndexRange(mesh->totpoly)) {
if (mesh->pdata.layers[i].type == CD_SCULPT_FACE_SETS) {
faceset_data = mesh->pdata.layers[i].data;
mesh->pdata.layers[i].data = nullptr;
CustomData_free_layer(&mesh->pdata, CD_SCULPT_FACE_SETS, mesh->totpoly, i);
break;
}
}
CustomData_update_typemap(&mesh->pdata);
if (faceset_data != nullptr) {
CustomData_add_layer_named(&mesh->pdata, CD_PROP_INT32, CD_ASSIGN, faceset_data, mesh->totpoly, ".sculpt_face_set");
}
}
/** \} */