allocate bmesh data from known sizes where possible (was still using defaults in...
authorCampbell Barton <ideasman42@gmail.com>
Tue, 24 Sep 2013 03:31:00 +0000 (03:31 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 24 Sep 2013 03:31:00 +0000 (03:31 +0000)
add macros for initializing BMAllocTemplate's, also add assert on invalid use of bmesh_sfme()

source/blender/blenkernel/intern/mesh.c
source/blender/blenkernel/intern/modifiers_bmesh.c
source/blender/bmesh/intern/bmesh_construct.c
source/blender/bmesh/intern/bmesh_core.c
source/blender/bmesh/intern/bmesh_mesh.h
source/blender/editors/mesh/editmesh_utils.c
source/blender/editors/sculpt_paint/sculpt.c

index 8c179d17901fa56da74d8b28df98c045c1bce8df..2dacd58fef94185ffbd393f75db3818fffe5c378 100644 (file)
@@ -530,8 +530,9 @@ Mesh *BKE_mesh_copy(Mesh *me)
 BMesh *BKE_mesh_to_bmesh(Mesh *me, Object *ob)
 {
        BMesh *bm;
+       const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_ME(me);
 
-       bm = BM_mesh_create(&bm_mesh_allocsize_default);
+       bm = BM_mesh_create(&allocsize);
 
        BM_mesh_bm_from_me(bm, me, false, true, ob->shapenr);
 
index d1797810c8682482c15c333d24f6b5a36d898ad5..a9ff569e70a413f0dc24574a28308f2d74c073be 100644 (file)
@@ -232,8 +232,9 @@ BMEditMesh *DM_to_editbmesh(DerivedMesh *dm, BMEditMesh *existing, const bool do
 BMesh *DM_to_bmesh(DerivedMesh *dm, const bool calc_face_normal)
 {
        BMesh *bm;
+       const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_DM(dm);
 
-       bm = BM_mesh_create(&bm_mesh_allocsize_default);
+       bm = BM_mesh_create(&allocsize);
 
        DM_to_bmesh_ex(dm, bm, calc_face_normal);
 
index 60d9b62d6b9b1fecd77a279146fce5eacb497e57..930964667e91aff3e3b7404b3ebc9cb0ca2fa047 100644 (file)
@@ -911,10 +911,7 @@ BMesh *BM_mesh_copy(BMesh *bm_old)
        BMEditSelection *ese;
        BMIter iter;
        int i;
-       const BMAllocTemplate allocsize = {bm_old->totvert,
-                                          bm_old->totedge,
-                                          bm_old->totloop,
-                                          bm_old->totface};
+       const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_BM(bm_old);
 
        /* allocate a bmesh */
        bm_new = BM_mesh_create(&allocsize);
index 34e11f5c9f962a5d1124713dfac870bb7706b5ed..164a92125cd0c921e197efb7edf569ce33e50a9a 100644 (file)
@@ -1278,6 +1278,7 @@ BMFace *bmesh_sfme(BMesh *bm, BMFace *f, BMVert *v1, BMVert *v2,
        }
 
        if (!l_v1 || !l_v2) {
+               BLI_assert(0);
                return NULL;
        }
 
index efcd80b374b7ea6f8b83fea55e4013dd61f2f3fa..583b158929035b7ac9eaeceef0140068e555b2d1 100644 (file)
@@ -60,6 +60,13 @@ typedef struct BMAllocTemplate {
 extern const BMAllocTemplate bm_mesh_allocsize_default;
 extern const BMAllocTemplate bm_mesh_chunksize_default;
 
+#define BMALLOC_TEMPLATE_FROM_BM(bm) { (CHECK_TYPE_INLINE(bm, BMesh *), \
+       (bm)->totvert), (bm)->totedge, (bm)->totloop, (bm)->totface}
+#define BMALLOC_TEMPLATE_FROM_ME(me) { (CHECK_TYPE_INLINE(me, Mesh *), \
+       (me)->totvert), (me)->totedge, (me)->totloop, (me)->totpoly}
+#define BMALLOC_TEMPLATE_FROM_DM(dm) { (CHECK_TYPE_INLINE(dm, DerivedMesh *), \
+       (dm)->getNumVerts(dm)), (dm)->getNumEdges(dm), (dm)->getNumLoops(dm), (dm)->getNumPolys(dm)}
+
 enum {
        BM_MESH_CREATE_USE_TOOLFLAGS = (1 << 0)
 };
index a64a23a9f4a4475fd7e361c424f0a87d52859f57..e457f7c45af0f5769effce4bb8dc226a84dd35dc 100644 (file)
@@ -662,10 +662,7 @@ static void undoMesh_to_editbtMesh(void *umv, void *em_v, void *UNUSED(obdata))
        UndoMesh *um = umv;
        BMesh *bm;
 
-       const BMAllocTemplate allocsize = {um->me.totvert,
-                                          um->me.totedge,
-                                          um->me.totloop,
-                                          um->me.totpoly};
+       const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_ME(&um->me);
 
        ob->shapenr = em->bm->shapenr = um->shapenr;
 
index a557afcdf3d40e229f68b5132e37b0c5c11be673..e4853203dab63babfe19cb60a5f8ff550011bb87 100644 (file)
@@ -4677,10 +4677,7 @@ void sculpt_dynamic_topology_enable(bContext *C)
        Object *ob = CTX_data_active_object(C);
        SculptSession *ss = ob->sculpt;
        Mesh *me = ob->data;
-       const BMAllocTemplate allocsize = {me->totvert,
-                                          me->totedge,
-                                          me->totloop,
-                                          me->totpoly};
+       const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_ME(me);
 
        sculpt_pbvh_clear(ob);