[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11986] trunk/blender/source/blender/ blenkernel/intern/modifier.c: Fix for edgesplit crashes reported in bugs 6695 and 7142.

Ben Batt benbatt at gmail.com
Sun Sep 9 20:03:58 CEST 2007


Revision: 11986
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11986
Author:   artificer
Date:     2007-09-09 20:03:58 +0200 (Sun, 09 Sep 2007)

Log Message:
-----------
Fix for edgesplit crashes reported in bugs 6695 and 7142. The problem, as
found by Riku Palom?\195?\164ki, was that "bridge" vertices (which connect two or more
faces that don't share edges) were not being included in the maximum final
vertex count calculation (used for memory allocation, hence the crashes).

Unfortunately Riku's patch actually stopped bridge vertices from being split
correctly, so I have fixed the problem by adding the maximum number of vertices
that can be generated from bridge vertices to the maximum final vertex count.

Thanks to Riku Palom?\195?\164ki for finding the cause!

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/modifier.c

Modified: trunk/blender/source/blender/blenkernel/intern/modifier.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/modifier.c	2007-09-09 15:46:30 UTC (rev 11985)
+++ trunk/blender/source/blender/blenkernel/intern/modifier.c	2007-09-09 18:03:58 UTC (rev 11986)
@@ -2453,8 +2453,43 @@
 
 }
 
-static void split_single_verts(SmoothMesh *mesh)
+static int count_bridge_verts(SmoothMesh *mesh)
 {
+	int i, j, count = 0;
+
+	for(i = 0; i < mesh->num_faces; i++) {
+		SmoothFace *face = &mesh->faces[i];
+
+		for(j = 0; j < SMOOTHFACE_MAX_EDGES && face->edges[j]; j++) {
+			SmoothEdge *edge = face->edges[j];
+			SmoothEdge *next_edge;
+			SmoothVert *vert = edge->verts[1 - face->flip[j]];
+			int next = (j + 1) % SMOOTHFACE_MAX_EDGES;
+
+			/* wrap next around if at last edge */
+			if(!face->edges[next]) next = 0;
+
+			next_edge = face->edges[next];
+
+			/* if there are other faces sharing this vertex but not
+			 * these edges, the vertex will be split, so count it
+			 */
+			/* vert has to have at least one face (this one), so faces != 0 */
+			if(!edge->faces->next && !next_edge->faces->next
+			    && vert->faces->next) {
+				count++;
+			}
+		}
+	}
+
+	/* each bridge vert will be counted once per face that uses it,
+	 * so count is too high, but it's ok for now
+	 */
+	return count;
+}
+
+static void split_bridge_verts(SmoothMesh *mesh)
+{
 	int i,j;
 
 	for(i = 0; i < mesh->num_faces; i++) {
@@ -2501,6 +2536,7 @@
 	/* 2. count max number of elements to add */
 	tag_and_count_extra_edges(mesh, emd->split_angle, emd->flags, &max_edges);
 	max_verts = max_edges * 2 + mesh->max_verts;
+	max_verts += count_bridge_verts(mesh);
 	max_edges += mesh->max_edges;
 
 	/* 3. reallocate smoothmesh arrays & copy elements across */
@@ -2518,10 +2554,9 @@
 	printf("********** Post-edge-split **********\n");
 	smoothmesh_print(mesh);
 #endif
-#if 1
-	split_single_verts(mesh);
-#endif
 
+	split_bridge_verts(mesh);
+
 #ifdef EDGESPLIT_DEBUG_1
 	printf("********** Post-vert-split **********\n");
 	smoothmesh_print(mesh);





More information about the Bf-blender-cvs mailing list