[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [52383] trunk/blender/source/blender/bmesh /operators/bmo_wireframe.c: fix for crash in wireframe tool with verts that only have one boundary edge (degenerate cases - edge with 3+ faces using it).

Campbell Barton ideasman42 at gmail.com
Tue Nov 20 01:33:14 CET 2012


Revision: 52383
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=52383
Author:   campbellbarton
Date:     2012-11-20 00:33:11 +0000 (Tue, 20 Nov 2012)
Log Message:
-----------
fix for crash in wireframe tool with verts that only have one boundary edge (degenerate cases - edge with 3+ faces using it).

Modified Paths:
--------------
    trunk/blender/source/blender/bmesh/operators/bmo_wireframe.c

Modified: trunk/blender/source/blender/bmesh/operators/bmo_wireframe.c
===================================================================
--- trunk/blender/source/blender/bmesh/operators/bmo_wireframe.c	2012-11-19 23:52:24 UTC (rev 52382)
+++ trunk/blender/source/blender/bmesh/operators/bmo_wireframe.c	2012-11-20 00:33:11 UTC (rev 52383)
@@ -77,39 +77,60 @@
 		}
 	}
 
-	l_a = bm_edge_tag_faceloop(e_a);
-	l_b = bm_edge_tag_faceloop(e_b);
+	if (e_a && e_b) {
+		l_a = bm_edge_tag_faceloop(e_a);
+		l_b = bm_edge_tag_faceloop(e_b);
 
-	/* average edge face normal */
-	add_v3_v3v3(no_face, l_a->f->no, l_b->f->no);
+		/* average edge face normal */
+		add_v3_v3v3(no_face, l_a->f->no, l_b->f->no);
 
-	/* average edge direction */
-	v_a = BM_edge_other_vert(e_a, v);
-	v_b = BM_edge_other_vert(e_b, v);
+		/* average edge direction */
+		v_a = BM_edge_other_vert(e_a, v);
+		v_b = BM_edge_other_vert(e_b, v);
 
-	sub_v3_v3v3(tvec_a, v->co, v_a->co);
-	sub_v3_v3v3(tvec_b, v_b->co, v->co);
-	normalize_v3(tvec_a);
-	normalize_v3(tvec_b);
-	add_v3_v3v3(no_edge, tvec_a, tvec_b); /* not unit length but this is ok */
+		sub_v3_v3v3(tvec_a, v->co, v_a->co);
+		sub_v3_v3v3(tvec_b, v_b->co, v->co);
+		normalize_v3(tvec_a);
+		normalize_v3(tvec_b);
+		add_v3_v3v3(no_edge, tvec_a, tvec_b); /* not unit length but this is ok */
 
+		/* check are we flipped the right way */
+		BM_edge_calc_face_tangent(e_a, l_a, tvec_a);
+		BM_edge_calc_face_tangent(e_b, l_b, tvec_b);
+		add_v3_v3(tvec_a, tvec_b);
 
+		*r_va_other = v_a;
+		*r_vb_other = v_b;
+	}
+	else {
+		/* degenerate case - vertex connects a boundary edged face to other faces,
+		 * so we have only one boundary face - only use it for calculations */
+		l_a = bm_edge_tag_faceloop(e_a);
+
+		copy_v3_v3(no_face, l_a->f->no);
+
+		/* edge direction */
+		v_a = BM_edge_other_vert(e_a, v);
+		v_b = NULL;
+
+		sub_v3_v3v3(no_edge, v->co, v_a->co);
+
+		/* check are we flipped the right way */
+		BM_edge_calc_face_tangent(e_a, l_a, tvec_a);
+
+		*r_va_other = NULL;
+		*r_vb_other = NULL;
+	}
+
 	/* find the normal */
 	cross_v3_v3v3(r_no, no_edge, no_face);
 	normalize_v3(r_no);
 
-	/* check are we flipped the right way */
-	BM_edge_calc_face_tangent(e_a, l_a, tvec_a);
-	BM_edge_calc_face_tangent(e_b, l_b, tvec_b);
-	add_v3_v3(tvec_a, tvec_b);
-
 	if (dot_v3v3(r_no, tvec_a) > 0.0f) {
 		negate_v3(r_no);
 	}
 
 	copy_v3_v3(r_no_face, no_face);
-	*r_va_other = v_a;
-	*r_vb_other = v_b;
 }
 
 /* check if we are the only tagged loop-face around this edge */
@@ -269,10 +290,12 @@
 							/* similar to code above but different angle calc */
 							fac = inset;
 							if (use_even_offset) {
-								fac *= shell_angle_to_dist(((float)M_PI - angle_on_axis_v3v3v3_v3(va_other->co,
-								                                                                  l_pair[i]->v->co,
-								                                                                  vb_other->co,
-								                                                                  no_face)) * 0.5f);
+								if (va_other) {  /* for verts with only one boundary edge - this will be NULL */
+									fac *= shell_angle_to_dist(((float)M_PI - angle_on_axis_v3v3v3_v3(va_other->co,
+									                                                                  l_pair[i]->v->co,
+									                                                                  vb_other->co,
+									                                                                  no_face)) * 0.5f);
+								}
 							}
 							if (use_relative_offset) {
 								fac *= verts_relfac[BM_elem_index_get(l_pair[i]->v)];




More information about the Bf-blender-cvs mailing list