[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33013] trunk/blender/source/blender/ modifiers/intern/MOD_array.c: Bugfix #19534

Ton Roosendaal ton at blender.org
Thu Nov 11 16:33:28 CET 2010


Revision: 33013
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33013
Author:   ton
Date:     2010-11-11 16:33:28 +0100 (Thu, 11 Nov 2010)

Log Message:
-----------
Bugfix #19534

Crash in Array Modifier. The merging-vertices option 
(mysteriously named "First Last") caused invalid indices in
faces to exist. This commit solves the crash, but not the
cause. For that Ben Batt's assistance is needed.

Modified Paths:
--------------
    trunk/blender/source/blender/modifiers/intern/MOD_array.c

Modified: trunk/blender/source/blender/modifiers/intern/MOD_array.c
===================================================================
--- trunk/blender/source/blender/modifiers/intern/MOD_array.c	2010-11-11 14:13:58 UTC (rev 33012)
+++ trunk/blender/source/blender/modifiers/intern/MOD_array.c	2010-11-11 15:33:28 UTC (rev 33013)
@@ -151,6 +151,30 @@
 	return max_co - min_co;
 }
 
+/* XXX This function fixes bad merging code, in some cases removing vertices creates indices > maxvert */
+
+static int test_index_face_maxvert(MFace *mface, CustomData *fdata, int mfindex, int nr, int maxvert)
+{
+	if(mface->v1 >= maxvert) {
+		// printf("bad index in array\n");
+		mface->v1= maxvert - 1;
+	}
+	if(mface->v2 >= maxvert) {
+		// printf("bad index in array\n");
+		mface->v2= maxvert - 1;
+	}
+	if(mface->v3 >= maxvert) {
+		// printf("bad index in array\n");
+		mface->v3= maxvert - 1;
+	}
+	if(mface->v4 >= maxvert) {
+		// printf("bad index in array\n");
+		mface->v4= maxvert - 1;
+	}
+	
+	return test_index_face(mface, fdata, mfindex, nr);
+}
+
 typedef struct IndexMapEntry {
 	/* the new vert index that this old vert index maps to */
 	int new;
@@ -485,7 +509,7 @@
 			  if(inMF.v4 && indexMap[inMF.v4].merge_final)
 				  mf->v4 = calc_mapping(indexMap, indexMap[inMF.v4].merge, count-1);
 
-			  if(test_index_face(mf, &result->faceData, numFaces, inMF.v4?4:3) < 3)
+			  if(test_index_face_maxvert(mf, &result->faceData, numFaces, inMF.v4?4:3, numVerts) < 3)
 				  continue;
 
 			  numFaces++;
@@ -509,7 +533,7 @@
 				  if (inMF.v4)
 					  mf2->v4 = calc_mapping(indexMap, inMF.v4, j);
 
-				  test_index_face(mf2, &result->faceData, numFaces, inMF.v4?4:3);
+				  test_index_face_maxvert(mf2, &result->faceData, numFaces, inMF.v4?4:3, numVerts);
 				  numFaces++;
 
 				  /* if the face has fewer than 3 vertices, don't create it */
@@ -605,8 +629,8 @@
 				  if(mface[numFaces].v4) {
 					  mface[numFaces].v4 = vert_map[mface[numFaces].v4];
 
-					  test_index_face(&mface[numFaces], &result->faceData,
-									  numFaces, 4);
+					  test_index_face_maxvert(&mface[numFaces], &result->faceData,
+									  numFaces, 4, numVerts);
 				  }
 				  else
 				  {





More information about the Bf-blender-cvs mailing list