BMesh: avoid recursion for BM_mesh_edgenet, runs out stack memory on large nets
authorCampbell Barton <ideasman42@gmail.com>
Sun, 8 Jun 2014 12:20:03 +0000 (22:20 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 8 Jun 2014 12:20:03 +0000 (22:20 +1000)
source/blender/bmesh/tools/bmesh_edgenet.c

index ddf43949258cffc6a0c6b4d01ae6ed33f9ab6360..a08aa6184b5e31f6b9c463e98dbd175ebf517992 100644 (file)
@@ -203,12 +203,18 @@ static BMEdge *bm_edgenet_path_step(
         BMVert *v_curr, LinkNode **v_ls,
         VertNetInfo *vnet_info, BLI_mempool *path_pool)
 {
-       const VertNetInfo *vn_curr = &vnet_info[BM_elem_index_get(v_curr)];
+       const VertNetInfo *vn_curr;
 
        BMEdge *e;
        BMIter iter;
-       unsigned int tot = 0;
-       unsigned int v_ls_tot = 0;
+       unsigned int tot;
+       unsigned int v_ls_tot;
+
+
+begin:
+       tot = 0;
+       v_ls_tot = 0;
+       vn_curr = &vnet_info[BM_elem_index_get(v_curr)];
 
        BM_ITER_ELEM (e, &iter, v_curr, BM_EDGES_OF_VERT) {
                BMVert *v_next = BM_edge_other_vert(e, v_curr);
@@ -256,7 +262,12 @@ static BMEdge *bm_edgenet_path_step(
        /* trick to walk along wire-edge paths */
        if (v_ls_tot == 1 && tot == 1) {
                v_curr = BLI_linklist_pop_pool(v_ls, path_pool);
+               /* avoid recursion, can crash on very large nets */
+#if 0
                bm_edgenet_path_step(v_curr, v_ls, vnet_info, path_pool);
+#else
+               goto begin;
+#endif
        }
 
        return NULL;