[Bf-blender-cvs] [320a1b6f354] temp_bmesh_multires: Fix bug in previous commit; customdata_bmesh_set_default now ignores CD_MESH_ID layers

Joseph Eagar noreply at git.blender.org
Mon Jul 12 05:28:38 CEST 2021


Commit: 320a1b6f35438f3211f1f49ee4ef0357ea1a07e8
Author: Joseph Eagar
Date:   Sun Jul 11 23:28:19 2021 -0400
Branches: temp_bmesh_multires
https://developer.blender.org/rB320a1b6f35438f3211f1f49ee4ef0357ea1a07e8

Fix bug in previous commit; customdata_bmesh_set_default now ignores
CD_MESH_ID layers

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

M	source/blender/blenkernel/intern/customdata.c
M	source/blender/bmesh/intern/bmesh_construct.c
M	source/blender/bmesh/intern/bmesh_log.c
M	source/blender/makesdna/DNA_customdata_types.h

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

diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index c07c75b7745..a384eec4156 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -3866,10 +3866,11 @@ static void CustomData_bmesh_set_default_n(CustomData *data, void **block, int n
   int offset = data->layers[n].offset;
   const LayerTypeInfo *typeInfo = layerType_getInfo(data->layers[n].type);
 
-  /*
-  if (data->layers[n].flag & CD_FLAG_ELEM_NOCOPY) {
+  /* can't allow this to be called on CD_MESH_ID */
+
+  if (data->layers[n].type == CD_MESH_ID) {
     return;
-  }*/
+  }
 
   if (typeInfo->set_default) {
     typeInfo->set_default(POINTER_OFFSET(*block, offset), 1);
diff --git a/source/blender/bmesh/intern/bmesh_construct.c b/source/blender/bmesh/intern/bmesh_construct.c
index ea144e1daea..6dc1359b5ff 100644
--- a/source/blender/bmesh/intern/bmesh_construct.c
+++ b/source/blender/bmesh/intern/bmesh_construct.c
@@ -40,10 +40,14 @@
 
 #define SELECT 1
 
+static const int _typemap[] = {0, 0, 1, 0, 2, 0, 0, 0, 3};
+
 static void bm_assign_id_intern(BMesh *bm, BMElem *elem, uint id)
 {
-  BM_ELEM_CD_SET_INT(elem, bm->idmap.cd_id_off[elem->head.htype], id);
+  // CustomData *cdata = &bm->vdata + _typemap[elem->head.htype];
+  // int cd_id_off = cdata->layers[cdata->typemap[CD_MESH_ID]].offset;
 
+  BM_ELEM_CD_SET_INT(elem, bm->idmap.cd_id_off[elem->head.htype], id);
   bm->idmap.maxid = MAX2(bm->idmap.maxid, id);
 
   if (bm->idmap.flag & BM_HAS_ID_MAP) {
@@ -88,7 +92,9 @@ void bm_free_id(BMesh *bm, BMElem *elem)
   }
 
   uint id = BM_ELEM_CD_GET_INT(elem, bm->idmap.cd_id_off[elem->head.htype]);
-  range_tree_uint_retake(bm->idmap.idtree, id);
+  if (range_tree_uint_has(bm->idmap.idtree, id)) {
+    range_tree_uint_release(bm->idmap.idtree, id);
+  }
 
   if ((bm->idmap.flag & BM_HAS_ID_MAP) && bm->idmap.map && id >= 0 && id < bm->idmap.map_size) {
     bm->idmap.map[id] = NULL;
diff --git a/source/blender/bmesh/intern/bmesh_log.c b/source/blender/bmesh/intern/bmesh_log.c
index a3086e00fe3..2237d5629f4 100644
--- a/source/blender/bmesh/intern/bmesh_log.c
+++ b/source/blender/bmesh/intern/bmesh_log.c
@@ -303,7 +303,7 @@ static void bm_log_vert_customdata(
   CustomData_bmesh_copy_data(&bm->vdata, &entry->vdata, v->head.data, &lv->customdata);
 
   // forcibly copy id
-  bm_log_copy_id(&bm->vdata, (BMElem *)v, lv->customdata);
+  // bm_log_copy_id(&bm->vdata, (BMElem *)v, lv->customdata);
 
 #endif
 }
@@ -326,7 +326,7 @@ static void bm_log_face_customdata(BMesh *bm, BMLog *log, BMFace *f, BMLogFace *
   CustomData_bmesh_copy_data(&bm->pdata, &entry->pdata, f->head.data, &lf->customdata_f);
 
   // forcibly copy id
-  bm_log_copy_id(&bm->pdata, (BMElem *)f, lf->customdata_f);
+  // bm_log_copy_id(&bm->pdata, (BMElem *)f, lf->customdata_f);
 
   BMLoop *l1 = f->l_first;
   BMLoop *l2 = f->l_first->next;
@@ -436,12 +436,19 @@ static BMLogFace *bm_log_face_alloc(BMLog *log, BMFace *f)
 static void bm_log_verts_unmake_pre(
     BMesh *bm, BMLog *log, GHash *verts, BMLogEntry *entry, BMLogCallbacks *callbacks)
 {
+  const int cd_vert_mask_offset = CustomData_get_offset(&bm->vdata, CD_PAINT_MASK);
+
   GHashIterator gh_iter;
   GHASH_ITER (gh_iter, verts) {
     void *key = BLI_ghashIterator_getKey(&gh_iter);
+    BMLogVert *lv = BLI_ghashIterator_getValue(&gh_iter);
     uint id = POINTER_AS_UINT(key);
     BMVert *v = bm_log_vert_from_id(log, id);
 
+    /* Ensure the log has the final values of the vertex before
+     * deleting it */
+    bm_log_vert_bmvert_copy(log, entry, lv, v, cd_vert_mask_offset, true);
+
     if (callbacks) {
       callbacks->on_vert_kill(v, callbacks->userdata);
     }
@@ -460,15 +467,11 @@ static void bm_log_verts_unmake(
     uint id = POINTER_AS_UINT(key);
     BMVert *v = bm_log_vert_from_id(log, id);
 
-    /* Ensure the log has the final values of the vertex before
-     * deleting it */
-    bm_log_vert_bmvert_copy(log, entry, lv, v, cd_vert_mask_offset, true);
-
     BM_vert_kill(bm, v);
   }
 }
 
-static void bm_log_faces_unmake(
+ATTR_NO_OPT static void bm_log_faces_unmake(
     BMesh *bm, BMLog *log, GHash *faces, BMLogEntry *entry, BMLogCallbacks *callbacks)
 {
   GHashIterator gh_iter;
@@ -498,7 +501,7 @@ static void bm_log_faces_unmake(
       CustomData_bmesh_copy_data(&bm->pdata, &entry->pdata, f->head.data, &lf->customdata_f);
 
       // forcibly copy id
-      bm_log_copy_id(&bm->pdata, (BMElem *)f, lf->customdata_f);
+      // bm_log_copy_id(&bm->pdata, (BMElem *)f, lf->customdata_f);
     }
 
     BMLoop *ls[3] = {f->l_first, f->l_first->next, f->l_first->prev};
@@ -554,7 +557,7 @@ static void bm_log_verts_restore(
   }
 }
 
-static void bm_log_faces_restore(
+ATTR_NO_OPT static void bm_log_faces_restore(
     BMesh *bm, BMLog *log, GHash *faces, BMLogEntry *entry, BMLogCallbacks *callbacks)
 {
   GHashIterator gh_iter;
@@ -568,6 +571,24 @@ static void bm_log_faces_restore(
     };
     BMFace *f;
 
+    if (!v[0] || !v[1] || !v[2]) {
+      BMIter iter;
+      BMVert *v2;
+      const int cd_id = bm->idmap.cd_id_off[BM_VERT];
+
+      BM_ITER_MESH (v2, &iter, bm, BM_VERTS_OF_MESH) {
+        int id = BM_ELEM_CD_GET_INT(v2, cd_id);
+
+        for (int i = 0; i < 3; i++) {
+          if (!v[i] && lf->v_ids[i] == (uint)id) {
+            printf("found vertex\n");
+          }
+        }
+      }
+      printf("Undo error! %p %p %p\n", v[0], v[1], v[2]);
+      continue;
+    }
+
     f = BM_face_create_verts(bm, v, 3, NULL, BM_CREATE_SKIP_ID, true);
     f->head.hflag = lf->hflag;
 
diff --git a/source/blender/makesdna/DNA_customdata_types.h b/source/blender/makesdna/DNA_customdata_types.h
index 3a0770f6434..19e9aace7c3 100644
--- a/source/blender/makesdna/DNA_customdata_types.h
+++ b/source/blender/makesdna/DNA_customdata_types.h
@@ -248,8 +248,7 @@ enum {
   CD_FLAG_EXTERNAL = (1 << 3),
   /* Indicates external data is read into memory */
   CD_FLAG_IN_MEMORY = (1 << 4),
-  CD_FLAG_ELEM_NOCOPY =
-      (1 << 5),  // disables CustomData_bmesh_copy_data and CustomData_bmesh_set_default_n.
+  CD_FLAG_ELEM_NOCOPY = (1 << 5),  // disables CustomData_bmesh_copy_data.
 };
 
 /* Limits */



More information about the Bf-blender-cvs mailing list