Commit: e324172d9ca6690e8bd2c0a53f0f7ad529d8e241
Author: Bastien Montagne
Date:   Fri Aug 11 15:53:38 2017 +0200
Branches: master
https://developer.blender.org/rBe324172d9ca6690e8bd2c0a53f0f7ad529d8e241

Fix transform snap code using 'allocated' flags to get verts/edges/etc. arrays 
again from DM.

This was... horribly wrong, CDDM will often *not* need to allocate
anything to return arrays of mesh items! Just check whether array
pointer is NULL.

Also, remove `DM_get_looptri_array`, that one is useless currently,
`dm->getLoopTriArray` will always return cached array (computing it if
needed).

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

M       source/blender/blenkernel/BKE_DerivedMesh.h
M       source/blender/blenkernel/intern/DerivedMesh.c
M       source/blender/blenkernel/intern/bvhutils.c
M       source/blender/blenkernel/intern/mesh_remap.c
M       source/blender/editors/transform/transform_snap_object.c

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

diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h 
b/source/blender/blenkernel/BKE_DerivedMesh.h
index 63ff1149a68..a31a51f9402 100644
--- a/source/blender/blenkernel/BKE_DerivedMesh.h
+++ b/source/blender/blenkernel/BKE_DerivedMesh.h
@@ -832,11 +832,5 @@ struct MEdge *DM_get_edge_array(struct DerivedMesh *dm, 
bool *r_allocated);
 struct MLoop *DM_get_loop_array(struct DerivedMesh *dm, bool *r_allocated);
 struct MPoly *DM_get_poly_array(struct DerivedMesh *dm, bool *r_allocated);
 struct MFace *DM_get_tessface_array(struct DerivedMesh *dm, bool *r_allocated);
-const MLoopTri *DM_get_looptri_array(
-        DerivedMesh *dm,
-        const MVert *mvert,
-        const MPoly *mpoly, int mpoly_len,
-        const MLoop *mloop, int mloop_len,
-        bool *r_allocated);
 
 #endif  /* __BKE_DERIVEDMESH_H__ */
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c 
b/source/blender/blenkernel/intern/DerivedMesh.c
index 9e33dd56b00..17e805cef70 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -4399,35 +4399,3 @@ MFace *DM_get_tessface_array(DerivedMesh *dm, bool 
*r_allocated)
 
        return mface;
 }
-
-const MLoopTri *DM_get_looptri_array(
-        DerivedMesh *dm,
-        const MVert *mvert,
-        const MPoly *mpoly, int mpoly_len,
-        const MLoop *mloop, int mloop_len,
-        bool *r_allocated)
-{
-       const MLoopTri *looptri = dm->getLoopTriArray(dm);
-       *r_allocated = false;
-
-       if (looptri == NULL) {
-               if (mpoly_len > 0) {
-                       const int looptris_num = poly_to_tri_count(mpoly_len, 
mloop_len);
-                       MLoopTri *looptri_data;
-
-                       looptri_data = MEM_mallocN(sizeof(MLoopTri) * 
looptris_num, __func__);
-
-                       BKE_mesh_recalc_looptri(
-                               mloop, mpoly,
-                               mvert,
-                               mloop_len, mpoly_len,
-                               looptri_data);
-
-                       looptri = looptri_data;
-
-                       *r_allocated = true;
-               }
-       }
-
-       return looptri;
-}
diff --git a/source/blender/blenkernel/intern/bvhutils.c 
b/source/blender/blenkernel/intern/bvhutils.c
index c1fad4f80c8..775499304d4 100644
--- a/source/blender/blenkernel/intern/bvhutils.c
+++ b/source/blender/blenkernel/intern/bvhutils.c
@@ -1137,7 +1137,6 @@ BVHTree *bvhtree_from_mesh_looptri(
        const MLoopTri *looptri = NULL;
        bool vert_allocated = false;
        bool loop_allocated = false;
-       bool looptri_allocated = false;
 
        BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_READ);
        tree = bvhcache_find(dm->bvhCache, BVHTREE_FROM_LOOPTRI);
@@ -1150,12 +1149,7 @@ BVHTree *bvhtree_from_mesh_looptri(
        mpoly = DM_get_poly_array(dm, &poly_allocated);
 
        mloop = DM_get_loop_array(dm, &loop_allocated);
-       looptri = DM_get_looptri_array(
-               dm,
-               mvert,
-               mpoly, dm->getNumPolys(dm),
-               mloop, dm->getNumLoops(dm),
-               &looptri_allocated);
+       looptri = dm->getLoopTriArray(dm);
 
        if (poly_allocated) {
                MEM_freeN(mpoly);
@@ -1193,7 +1187,7 @@ BVHTree *bvhtree_from_mesh_looptri(
                        data, tree, true, epsilon,
                        mvert, vert_allocated,
                        mloop, loop_allocated,
-                       looptri, looptri_allocated);
+                       looptri, false);
        }
        else {
                if (vert_allocated) {
@@ -1202,9 +1196,6 @@ BVHTree *bvhtree_from_mesh_looptri(
                if (loop_allocated) {
                        MEM_freeN(mloop);
                }
-               if (looptri_allocated) {
-                       MEM_freeN((void *)looptri);
-               }
                memset(data, 0, sizeof(*data));
        }
 
diff --git a/source/blender/blenkernel/intern/mesh_remap.c 
b/source/blender/blenkernel/intern/mesh_remap.c
index c5fa9b15896..624898d47a5 100644
--- a/source/blender/blenkernel/intern/mesh_remap.c
+++ b/source/blender/blenkernel/intern/mesh_remap.c
@@ -1184,7 +1184,6 @@ void BKE_mesh_remap_calc_loops_from_dm(
                bool polys_allocated_src;
                MPoly *polys_src = DM_get_poly_array(dm_src, 
&polys_allocated_src);
                const int num_polys_src = dm_src->getNumPolys(dm_src);
-               bool looptri_allocated_src = false;
                const MLoopTri *looptri_src = NULL;
                int num_looptri_src = 0;
 
@@ -1379,12 +1378,7 @@ void BKE_mesh_remap_calc_loops_from_dm(
                                        dm_src->dirty |= dirty_tess_flag;
                                }
 
-                               looptri_src = DM_get_looptri_array(
-                                       dm_src,
-                                       verts_src,
-                                       polys_src, num_polys_src,
-                                       loops_src, num_loops_src,
-                                       &looptri_allocated_src);
+                               looptri_src = dm_src->getLoopTriArray(dm_src);
                                num_looptri_src = dm_src->getNumLoopTri(dm_src);
                                looptri_active = 
BLI_BITMAP_NEW((size_t)num_looptri_src, __func__);
 
@@ -1403,7 +1397,7 @@ void BKE_mesh_remap_calc_loops_from_dm(
                                                &treedata[tindex],
                                                verts_src, verts_allocated_src,
                                                loops_src, loops_allocated_src,
-                                               looptri_src, num_looptri_src, 
looptri_allocated_src,
+                                               looptri_src, num_looptri_src, 
false,
                                                looptri_active, 
num_looptri_active, bvh_epsilon, 2, 6);
                                        if (verts_allocated_src) {
                                                verts_allocated_src = false;  
/* Only 'give' our verts once, to first tree! */
@@ -1411,9 +1405,6 @@ void BKE_mesh_remap_calc_loops_from_dm(
                                        if (loops_allocated_src) {
                                                loops_allocated_src = false;  
/* Only 'give' our loops once, to first tree! */
                                        }
-                                       if (looptri_allocated_src) {
-                                               looptri_allocated_src = false;  
/* Only 'give' our looptri once, to first tree! */
-                                       }
                                }
 
                                MEM_freeN(looptri_active);
@@ -1928,9 +1919,6 @@ void BKE_mesh_remap_calc_loops_from_dm(
                if (polys_allocated_src) {
                        MEM_freeN(polys_src);
                }
-               if (looptri_allocated_src) {
-                       MEM_freeN((void *)looptri_src);
-               }
                if (vert_to_loop_map_src) {
                        MEM_freeN(vert_to_loop_map_src);
                }
diff --git a/source/blender/editors/transform/transform_snap_object.c 
b/source/blender/editors/transform/transform_snap_object.c
index 0fe121252be..fff92a8385a 100644
--- a/source/blender/editors/transform/transform_snap_object.c
+++ b/source/blender/editors/transform/transform_snap_object.c
@@ -436,21 +436,18 @@ static bool raycastDerivedMesh(
                                free_bvhtree_from_mesh(treedata);
                        }
                        else {
-                               if (!treedata->vert_allocated) {
+                               if (treedata->vert == NULL) {
                                        treedata->vert = DM_get_vert_array(dm, 
&treedata->vert_allocated);
                                }
-                               if (!treedata->loop_allocated) {
+                               if (treedata->loop == NULL) {
                                        treedata->loop = DM_get_loop_array(dm, 
&treedata->loop_allocated);
                                }
-                               if (!treedata->looptri_allocated) {
-                                       if (!sod->poly_allocated) {
+                               if (treedata->looptri == NULL) {
+                                       if (sod->mpoly == NULL) {
                                                sod->mpoly = 
DM_get_poly_array(dm, &sod->poly_allocated);
                                        }
-                                       treedata->looptri = 
DM_get_looptri_array(
-                                               dm, treedata->vert,
-                                               sod->mpoly, dm->getNumPolys(dm),
-                                               treedata->loop, 
dm->getNumLoops(dm),
-                                               &treedata->looptri_allocated);
+                                       treedata->looptri = 
dm->getLoopTriArray(dm);
+                                       treedata->looptri_allocated = false;
                                }
                        }
                }
@@ -1709,10 +1706,10 @@ static bool snapDerivedMesh(
                                free_bvhtree_from_mesh(treedata);
                        }
                        else {
-                               if (!treedata->vert_allocated) {
+                               if (treedata->vert == NULL) {
                                        treedata->vert = DM_get_vert_array(dm, 
&treedata->vert_allocated);
                                }
-                               if ((tree_index == 1) && 
!treedata->edge_allocated) {
+                               if ((tree_index == 1) && (treedata->edge == 
NULL)) {
                                        treedata->edge = DM_get_edge_array(dm, 
&treedata->edge_allocated);
                                }
                        }

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to