[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45101] trunk/blender/source/blender/bmesh /intern/bmesh_core.c: fix [#30632] Edge Split Modifier ( creates invalid mesh)

Campbell Barton ideasman42 at gmail.com
Fri Mar 23 06:44:09 CET 2012


Revision: 45101
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45101
Author:   campbellbarton
Date:     2012-03-23 05:43:56 +0000 (Fri, 23 Mar 2012)
Log Message:
-----------
fix [#30632] Edge Split Modifier (creates invalid mesh)

bug was caused by modifying loops vert value in a BM_LOOPS_OF_VERT iterator.

Modified Paths:
--------------
    trunk/blender/source/blender/bmesh/intern/bmesh_core.c

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_core.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_core.c	2012-03-23 05:18:03 UTC (rev 45100)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_core.c	2012-03-23 05:43:56 UTC (rev 45101)
@@ -1784,7 +1784,6 @@
 
 		maxindex++;
 	}
-	BLI_array_free(stack);
 
 	/* Make enough verts to split v for each group */
 	verts = MEM_callocN(sizeof(BMVert *) * maxindex, __func__);
@@ -1794,6 +1793,7 @@
 	}
 
 	/* Replace v with the new verts in each group */
+#if 0
 	BM_ITER(l, &liter, bm, BM_LOOPS_OF_VERT, v) {
 		/* call first since its faster then a hash lookup */
 		if (l->v != v) {
@@ -1810,9 +1810,29 @@
 		 * towards vertex v, and another for the loop heading out from
 		 * vertex v. Only need to swap the vertex on one of those times,
 		 * on the outgoing loop. */
+
+		/* XXX - because this clobbers the iterator, this *whole* block is commented, see below */
 		l->v = verts[i];
 	}
+#else
+	/* note: this is the same as the commented code above *except* that it doesnt break iterator
+	 * by modifying data it loops over [#30632], this re-uses the 'stack' variable which is a bit
+	 * bad practice but save alloc'ing a new array - note, the comment above is useful, keep it
+	 * if you are tidying up code - campbell */
+	BLI_array_empty(stack);
+	BM_ITER(l, &liter, bm, BM_LOOPS_OF_VERT, v) {
+		if ((l->v == v) && (i = GET_INT_FROM_POINTER(BLI_ghash_lookup(visithash, l->e)))) {
+			BM_elem_index_set(l, i); /* would be nice to assign vert here but cant, so assign the vert index */
+			BLI_array_append(stack, (BMEdge *)l);
+		}
+	}
+	while ((l = (BMLoop *)(BLI_array_pop(stack)))) {
+		l->v = verts[BM_elem_index_get(l)];
+	}
+#endif
 
+	BLI_array_free(stack);
+
 	BM_ITER(e, &eiter, bm, BM_EDGES_OF_VERT, v) {
 		i = GET_INT_FROM_POINTER(BLI_ghash_lookup(visithash, e));
 		if (i == 0) {




More information about the Bf-blender-cvs mailing list