fix for crash in edgering subd when 3+ disconnected edge rings were found.
authorCampbell Barton <ideasman42@gmail.com>
Sun, 2 Jun 2013 17:02:56 +0000 (17:02 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 2 Jun 2013 17:02:56 +0000 (17:02 +0000)
source/blender/bmesh/operators/bmo_subdivide_edgering.c

index 871ebdf0feb5113064087719eee81732191eaccb..7f08ad2461a536a3d65e4a27005a323ba972e465 100644 (file)
@@ -249,18 +249,19 @@ static GHash *bm_edgering_pair_calc(BMesh *bm, ListBase *eloops_rim)
 
                                el_store_other = BLI_ghash_lookup(vert_eloop_gh, v_other);
 
 
                                el_store_other = BLI_ghash_lookup(vert_eloop_gh, v_other);
 
-                               BLI_assert(el_store != NULL);
-                               BLI_assert(el_store_other != NULL);
+                               /* in rare cases we cant find a match */
+                               if (el_store_other) {
+                                       pair_test.first = el_store;
+                                       pair_test.second = el_store_other;
 
 
-                               pair_test.first = el_store;
-                               pair_test.second = el_store_other;
+                                       if (pair_test.first > pair_test.second)
+                                               SWAP(const void *, pair_test.first, pair_test.second);
 
 
-                               if (pair_test.first > pair_test.second)
-                                       SWAP(const void *, pair_test.first, pair_test.second);
+                                       if (!BLI_ghash_haskey(eloop_pair_gh, &pair_test)) {
+                                               GHashPair *pair = BLI_ghashutil_pairalloc(pair_test.first, pair_test.second);
+                                               BLI_ghash_insert(eloop_pair_gh, pair, NULL);
+                                       }
 
 
-                               if (!BLI_ghash_haskey(eloop_pair_gh, &pair_test)) {
-                                       GHashPair *pair = BLI_ghashutil_pairalloc(pair_test.first, pair_test.second);
-                                       BLI_ghash_insert(eloop_pair_gh, pair, NULL);
                                }
                        }
                }
                                }
                        }
                }
@@ -268,6 +269,11 @@ static GHash *bm_edgering_pair_calc(BMesh *bm, ListBase *eloops_rim)
 
        BLI_ghash_free(vert_eloop_gh, NULL, NULL);
 
 
        BLI_ghash_free(vert_eloop_gh, NULL, NULL);
 
+       if (BLI_ghash_size(eloop_pair_gh) == 0) {
+               BLI_ghash_free(eloop_pair_gh, NULL, NULL);
+               eloop_pair_gh = NULL;
+       }
+
        return eloop_pair_gh;
 }
 
        return eloop_pair_gh;
 }
 
@@ -1151,15 +1157,26 @@ void bmo_subdivide_edgering_exec(BMesh *bm, BMOperator *op)
                                                  interp_mode, cuts, smooth, falloff_cache);
                        bm_edgering_pair_store_free(lpair, interp_mode);
                }
                                                  interp_mode, cuts, smooth, falloff_cache);
                        bm_edgering_pair_store_free(lpair, interp_mode);
                }
+               else {
+                       BMO_error_raise(bm, op, BMERR_INVALID_SELECTION,
+                                       "Edge-ring pair isn't connected");
+                       goto cleanup;
+               }
        }
        else {
                GHashIterator gh_iter;
                int i;
 
                GHash *eloop_pairs_gh = bm_edgering_pair_calc(bm, &eloops_rim);
        }
        else {
                GHashIterator gh_iter;
                int i;
 
                GHash *eloop_pairs_gh = bm_edgering_pair_calc(bm, &eloops_rim);
+               LoopPairStore **lpair_arr;
+
+               if (eloop_pairs_gh == NULL) {
+                       BMO_error_raise(bm, op, BMERR_INVALID_SELECTION,
+                                       "Edge-rings are not connected");
+                       goto cleanup;
+               }
 
 
-               const int eloop_pairs_len = BLI_ghash_size(eloop_pairs_gh);
-               LoopPairStore **lpair_arr = BLI_array_alloca(lpair_arr, eloop_pairs_len);
+               lpair_arr = BLI_array_alloca(lpair_arr, BLI_ghash_size(eloop_pairs_gh));
 
                /* first cache pairs */
                GHASH_ITER_INDEX (gh_iter, eloop_pairs_gh, i) {
 
                /* first cache pairs */
                GHASH_ITER_INDEX (gh_iter, eloop_pairs_gh, i) {