[Bf-blender-cvs] [9f96976] master: DerivedMesh: don't allocate a new material array each draw

Campbell Barton noreply at git.blender.org
Fri May 6 18:12:24 CEST 2016


Commit: 9f96976e597f165bc1de34fbc950519eb8074d36
Author: Campbell Barton
Date:   Sat May 7 01:58:28 2016 +1000
Branches: master
https://developer.blender.org/rB9f96976e597f165bc1de34fbc950519eb8074d36

DerivedMesh: don't allocate a new material array each draw

===================================================================

M	source/blender/blenkernel/intern/DerivedMesh.c

===================================================================

diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 57926e6..1ec714e 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -647,13 +647,15 @@ void DM_generate_tangent_tessface_data(DerivedMesh *dm, bool generate)
 void DM_update_materials(DerivedMesh *dm, Object *ob)
 {
 	int i, totmat = ob->totcol + 1; /* materials start from 1, default material is 0 */
-	dm->totmat = totmat;
 
-	/* invalidate old materials */
-	if (dm->mat)
-		MEM_freeN(dm->mat);
+	if (dm->totmat != totmat) {
+		dm->totmat = totmat;
+		/* invalidate old materials */
+		if (dm->mat)
+			MEM_freeN(dm->mat);
 
-	dm->mat = MEM_callocN(totmat * sizeof(*dm->mat), "DerivedMesh.mat");
+		dm->mat = MEM_mallocN(totmat * sizeof(*dm->mat), "DerivedMesh.mat");
+	}
 
 	/* we leave last material as empty - rationale here is being able to index
 	 * the materials by using the mf->mat_nr directly and leaving the last
@@ -661,6 +663,7 @@ void DM_update_materials(DerivedMesh *dm, Object *ob)
 	for (i = 0; i < totmat - 1; i++) {
 		dm->mat[i] = give_current_material(ob, i + 1);
 	}
+	dm->mat[i] = NULL;
 }
 
 MLoopUV *DM_paint_uvlayer_active_get(DerivedMesh *dm, int mat_nr)




More information about the Bf-blender-cvs mailing list