[Bf-blender-cvs] [d92edca8622] master: Fix: CustomData layers become unsorted in versioning

Baardaap noreply at git.blender.org
Thu Feb 2 09:54:40 CET 2023


Commit: d92edca86227b34c0899a523ce940c07b889ef9b
Author: Baardaap
Date:   Wed Feb 1 12:13:20 2023 +0100
Branches: master
https://developer.blender.org/rBd92edca86227b34c0899a523ce940c07b889ef9b

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

===================================================================

M	source/blender/blenkernel/intern/mesh_legacy_convert.cc

===================================================================

diff --git a/source/blender/blenkernel/intern/mesh_legacy_convert.cc b/source/blender/blenkernel/intern/mesh_legacy_convert.cc
index 5913751aac9..46de138fde7 100644
--- a/source/blender/blenkernel/intern/mesh_legacy_convert.cc
+++ b/source/blender/blenkernel/intern/mesh_legacy_convert.cc
@@ -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");
+  }
 }
 
 /** \} */



More information about the Bf-blender-cvs mailing list