More array modifier fixes.
authorNicholas Bishop <nicholasbishop@gmail.com>
Thu, 29 Mar 2012 11:31:44 +0000 (11:31 +0000)
committerNicholas Bishop <nicholasbishop@gmail.com>
Thu, 29 Mar 2012 11:31:44 +0000 (11:31 +0000)
* Skip calculation of merge indices if merging isn't enabled
* Clean up usage of BMesh operators to fix small memory leak
* Fix harmless BLI_assert in CustomData_bmesh_merge
* Another null-initialization fix in CustomData_bmesh_merge

source/blender/blenkernel/intern/customdata.c
source/blender/modifiers/intern/MOD_array.c

index 17a29d89d199c0f4f3be54753256619fe62750c3..638ba2ddc4d17f85bcbf84dd4510956cc8b68038 100644 (file)
@@ -2165,6 +2165,7 @@ void CustomData_bmesh_merge(CustomData *source, CustomData *dest,
        int t;
        
        CustomData_merge(source, dest, mask, alloctype, 0);
+       dest->pool = NULL;
        CustomData_bmesh_init_pool(dest, 512, htype);
 
        switch (htype) {
@@ -2198,6 +2199,7 @@ void CustomData_bmesh_merge(CustomData *source, CustomData *dest,
                /*ensure all current elements follow new customdata layout*/
                BM_ITER(f, &iter, bm, BM_FACES_OF_MESH, NULL) {
                        BM_ITER(l, &liter, bm, BM_LOOPS_OF_FACE, f) {
+                               tmp = NULL;
                                CustomData_bmesh_copy_data(&destold, dest, l->head.data, &tmp);
                                CustomData_bmesh_free_block(&destold, &l->head.data);
                                l->head.data = tmp;
index bf46c10b7200c711324bc90023a767abf1fa7d2c..41b1d18fc5f1b6840d1e7742d312d23987a4ecba 100644 (file)
@@ -337,15 +337,18 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd,
        BMO_push(em->bm, NULL);
        bmesh_edit_begin(em->bm, 0);
 
-       BMO_op_init(em->bm, &weld_op, "weldverts");
-       BMO_op_initf(em->bm, &dupe_op, "dupe geom=%avef");
-       old_dupe_op = dupe_op;
+       if (amd->flags & MOD_ARR_MERGE)
+               BMO_op_init(em->bm, &weld_op, "weldverts");
+       
        for (j=0; j < count - 1; j++) {
                BMVert *v, *v2, *v3;
                BMOpSlot *s1;
                BMOpSlot *s2;
 
-               BMO_op_initf(em->bm, &dupe_op, "dupe geom=%s", &old_dupe_op, j==0 ? "geom" : "newout");
+               if (j == 0)
+                       BMO_op_initf(em->bm, &dupe_op, "dupe geom=%avef");
+               else
+                       BMO_op_initf(em->bm, &dupe_op, "dupe geom=%s", &old_dupe_op, "newout");
                BMO_op_exec(em->bm, &dupe_op);
 
                s1 = BMO_slot_get(&dupe_op, "geom");
@@ -353,35 +356,38 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd,
 
                BMO_op_callf(em->bm, "transform mat=%m4 verts=%s", offset, &dupe_op, "newout");
 
-               /*calculate merge mapping*/
-               if (j == 0) {
-                       indexMap = find_doubles_index_map(em->bm, &dupe_op,
-                                                                                         amd, &indexLen);
-               }
+               if (amd->flags & MOD_ARR_MERGE) {
+                       /*calculate merge mapping*/
+                       if (j == 0) {
+                               indexMap = find_doubles_index_map(em->bm, &dupe_op,
+                                                                                                 amd, &indexLen);
+                       }
 
-               #define _E(s, i) ((BMVert **)(s)->data.buf)[i]
-               /* generate merge mapping using index map.  we do this by using the
-                * operator slots as lookup arrays.*/
-               #define E(i) (i) < s1->len ? _E(s1, i) : _E(s2, (i)-s1->len)
+                       #define _E(s, i) ((BMVert **)(s)->data.buf)[i]
+                       /* generate merge mapping using index map.  we do this by using the
+                        * operator slots as lookup arrays.*/
+                       #define E(i) (i) < s1->len ? _E(s1, i) : _E(s2, (i)-s1->len)
 
-               for (i=0; i<indexLen; i++) {
-                       if (!indexMap[i]) continue;
+                       for (i=0; i<indexLen; i++) {
+                               if (!indexMap[i]) continue;
 
-                       v = E(i);
-                       v2 = E(indexMap[i]-1);
+                               v = E(i);
+                               v2 = E(indexMap[i]-1);
 
-                       /* check in case the target vertex (v2) is already marked
-                          for merging */
-                       while((v3 = BMO_slot_map_ptr_get(em->bm, &weld_op, "targetmap", v2)))
-                               v2 = v3;
+                               /* check in case the target vertex (v2) is already marked
+                                  for merging */
+                               while((v3 = BMO_slot_map_ptr_get(em->bm, &weld_op, "targetmap", v2)))
+                                       v2 = v3;
 
-                       BMO_slot_map_ptr_insert(em->bm, &weld_op, "targetmap", v, v2);
-               }
+                               BMO_slot_map_ptr_insert(em->bm, &weld_op, "targetmap", v, v2);
+                       }
 
-               #undef E
-               #undef _E
+                       #undef E
+                       #undef _E
+               }
 
-               BMO_op_finish(em->bm, &old_dupe_op);
+               if (j != 0)
+                       BMO_op_finish(em->bm, &old_dupe_op);
                old_dupe_op = dupe_op;
        }
 
@@ -414,10 +420,10 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd,
        }
        /* done capping */
 
-       if (amd->flags & MOD_ARR_MERGE)
+       if (amd->flags & MOD_ARR_MERGE) {
                BMO_op_exec(em->bm, &weld_op);
-
-       BMO_op_finish(em->bm, &weld_op);
+               BMO_op_finish(em->bm, &weld_op);
+       }
 
        /* Bump the stack level back down to match the adjustment up above */
        BMO_pop(em->bm);