[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43703] branches/bmesh/blender/source/ blender/blenkernel/intern/mesh.c: avoid storing over allocated arrays in tesselated custom data, was reserving initial arrays wrong the wrong array length.

Campbell Barton ideasman42 at gmail.com
Thu Jan 26 00:59:39 CET 2012


Revision: 43703
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43703
Author:   campbellbarton
Date:     2012-01-25 23:59:28 +0000 (Wed, 25 Jan 2012)
Log Message:
-----------
avoid storing over allocated arrays in tesselated custom data, was reserving initial arrays wrong the wrong array length.

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

Modified: branches/bmesh/blender/source/blender/blenkernel/intern/mesh.c
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/intern/mesh.c	2012-01-25 22:55:12 UTC (rev 43702)
+++ branches/bmesh/blender/source/blender/blenkernel/intern/mesh.c	2012-01-25 23:59:28 UTC (rev 43703)
@@ -2251,8 +2251,8 @@
 
 	/* allocate the length of totfaces, avoid many small reallocs,
 	 * if all faces are tri's it will be correct, quads == 2x allocs */
-	BLI_array_reserve(mface_to_poly_map, totface);
-	BLI_array_reserve(mface, totface);
+	BLI_array_reserve(mface_to_poly_map, totpoly);
+	BLI_array_reserve(mface, totpoly);
 
 	mface_index = 0;
 	mp = mpoly;
@@ -2382,7 +2382,17 @@
 	CustomData_free(fdata, totface);
 	memset(fdata, 0, sizeof(CustomData));
 	totface = mface_index;
-	
+
+
+	/* note essential but without this we store over-alloc'd memory in the CustomData layers */
+	if (LIKELY((MEM_allocN_len(mface) / sizeof(*mface)) != totface)) {
+		mface = MEM_reallocN(mface, sizeof(*mface) * totface);
+		mface_to_poly_map = MEM_reallocN(mface_to_poly_map, sizeof(*mface_to_poly_map) * totface);
+		if (mface_orig_index) {
+			mface_orig_index = MEM_reallocN(mface_orig_index, sizeof(*mface_orig_index) * totface);
+		}
+	}
+
 	CustomData_add_layer(fdata, CD_MFACE, CD_ASSIGN, mface, totface);
 
 	/* CD_POLYINDEX will contain an array of indices from tessfaces to the polygons



More information about the Bf-blender-cvs mailing list