[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [46584] trunk/blender/source/blender/ blenkernel/intern/mesh.c: fix for own bad logic with polygon normal calculation, was reading one past the loop array (reported as bug #31431).

Campbell Barton ideasman42 at gmail.com
Sat May 12 23:01:26 CEST 2012


Revision: 46584
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46584
Author:   campbellbarton
Date:     2012-05-12 21:01:26 +0000 (Sat, 12 May 2012)
Log Message:
-----------
fix for own bad logic with polygon normal calculation, was reading one past the loop array (reported as bug #31431).

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

Modified: trunk/blender/source/blender/blenkernel/intern/mesh.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/mesh.c	2012-05-12 20:50:46 UTC (rev 46583)
+++ trunk/blender/source/blender/blenkernel/intern/mesh.c	2012-05-12 21:01:26 UTC (rev 46584)
@@ -2771,16 +2771,19 @@
 {
 	const int nverts = mpoly->totloop;
 	float const *v_prev = mvert[loopstart[nverts - 1].v].co;
-	float const *v_curr = mvert[loopstart->v].co;
-	float n[3] = {0.0f};
+	float const *v_curr;
 	int i;
 
+	zero_v3(normal);
+
 	/* Newell's Method */
-	for (i = 0; i < nverts; v_prev = v_curr, v_curr = mvert[loopstart[++i].v].co) {
-		add_newell_cross_v3_v3v3(n, v_prev, v_curr);
+	for (i = 0; i < nverts; i++) {
+		v_curr = mvert[loopstart[i].v].co;
+		add_newell_cross_v3_v3v3(normal, v_prev, v_curr);
+		v_prev = v_curr;
 	}
 
-	if (UNLIKELY(normalize_v3_v3(normal, n) == 0.0f)) {
+	if (UNLIKELY(normalize_v3(normal) == 0.0f)) {
 		normal[2] = 1.0f; /* other axis set to 0.0 */
 	}
 }
@@ -2818,16 +2821,19 @@
 {
 	const int nverts = mpoly->totloop;
 	float const *v_prev = vertex_coords[loopstart[nverts - 1].v];
-	float const *v_curr = vertex_coords[loopstart->v];
-	float n[3] = {0.0f};
+	float const *v_curr;
 	int i;
 
+	zero_v3(normal);
+
 	/* Newell's Method */
-	for (i = 0; i < nverts; v_prev = v_curr, v_curr = vertex_coords[loopstart[++i].v]) {
-		add_newell_cross_v3_v3v3(n, v_prev, v_curr);
+	for (i = 0; i < nverts; i++) {
+		v_curr = vertex_coords[loopstart[i].v];
+		add_newell_cross_v3_v3v3(normal, v_prev, v_curr);
+		v_prev = v_curr;
 	}
 
-	if (UNLIKELY(normalize_v3_v3(normal, n) == 0.0f)) {
+	if (UNLIKELY(normalize_v3(normal) == 0.0f)) {
 		normal[2] = 1.0f; /* other axis set to 0.0 */
 	}
 }




More information about the Bf-blender-cvs mailing list