fix for crash in grid-fill where it was possible for rail edges to overlap.
authorCampbell Barton <ideasman42@gmail.com>
Thu, 16 May 2013 15:28:57 +0000 (15:28 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 16 May 2013 15:28:57 +0000 (15:28 +0000)
source/blender/bmesh/intern/bmesh_edgeloop.c
source/blender/bmesh/intern/bmesh_edgeloop.h
source/blender/bmesh/operators/bmo_grid_fill.c

index 1ab7652502cd3466271b6c0dd6442880566709a3..7c5b20381abe99dba7f1268305b5c35de67986b5 100644 (file)
@@ -601,3 +601,24 @@ void BM_edgeloop_expand(BMesh *UNUSED(bm), BMEdgeLoopStore *el_store, int el_sto
 
        BLI_assert(el_store->len == el_store_len);
 }
+
+bool BM_edgeloop_overlap_check(struct BMEdgeLoopStore *el_store_a, struct BMEdgeLoopStore *el_store_b)
+{
+       LinkData *node;
+
+       /* init */
+       for (node = el_store_a->verts.first; node; node = node->next) {
+               BM_elem_flag_disable((BMVert *)node->data, BM_ELEM_INTERNAL_TAG);
+       }
+       for (node = el_store_b->verts.first; node; node = node->next) {
+               BM_elem_flag_enable((BMVert *)node->data, BM_ELEM_INTERNAL_TAG);
+       }
+
+       /* check 'a' */
+       for (node = el_store_a->verts.first; node; node = node->next) {
+               if (BM_elem_flag_test((BMVert *)node->data, BM_ELEM_INTERNAL_TAG)) {
+                       return true;
+               }
+       }
+       return false;
+}
index 50f85a3155ba8538353a2842d94f06a30bdb43c0..aa57fcfc47d85f65c997a2b50e69c9d023da6b97 100644 (file)
@@ -57,6 +57,8 @@ void                BM_edgeloop_calc_normal(BMesh *bm, struct BMEdgeLoopStore *e
 void                BM_edgeloop_flip(BMesh *bm, struct BMEdgeLoopStore *el_store);
 void                BM_edgeloop_expand(BMesh *bm, struct BMEdgeLoopStore *el_store, int el_store_len);
 
+bool                BM_edgeloop_overlap_check(struct BMEdgeLoopStore *el_store_a, struct BMEdgeLoopStore *el_store_b);
+
 #define BM_EDGELOOP_NEXT(el_store, elink) \
        (elink)->next ? elink->next : (BM_edgeloop_is_closed(el_store) ? BM_edgeloop_verts_get(el_store)->first : NULL)
 
index 05116c93a13254a0cd7c46be6eb697117bcd0ac8..21325cf05b233cf7e40ec6768463c71d09e142ad 100644 (file)
@@ -423,6 +423,12 @@ void bmo_grid_fill_exec(BMesh *bm, BMOperator *op)
                goto cleanup;
        }
 
+       if (BM_edgeloop_overlap_check(estore_rail_a, estore_rail_b)) {
+               BMO_error_raise(bm, op, BMERR_INVALID_SELECTION,
+                               "Connecting edge loops overlap");
+               goto cleanup;
+       }
+
        /* finally we have all edge loops needed */
        bm_grid_fill(bm, estore_a, estore_b, estore_rail_a, estore_rail_b,
                     mat_nr, use_smooth);