[Bf-blender-cvs] [1c811d9] master: Make material array account for mesh/object storage of materials

Antony Riakiotakis noreply at git.blender.org
Wed Apr 9 17:38:04 CEST 2014


Commit: 1c811d96b22b0880c118aca21f151e593fc45fc2
Author: Antony Riakiotakis
Date:   Wed Apr 9 18:37:54 2014 +0300
https://developer.blender.org/rB1c811d96b22b0880c118aca21f151e593fc45fc2

Make material array account for mesh/object storage of materials

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

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

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

diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index dcaf102..c8862e1 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -350,6 +350,12 @@ int DM_release(DerivedMesh *dm)
 		CustomData_free(&dm->loopData, dm->numLoopData);
 		CustomData_free(&dm->polyData, dm->numPolyData);
 
+		if (dm->mat) {
+			MEM_freeN(dm->mat);
+			dm->mat = NULL;
+			dm->totmat = 0;
+		}
+
 		return 1;
 	}
 	else {
@@ -485,8 +491,18 @@ void DM_update_tessface_data(DerivedMesh *dm)
 
 void DM_update_materials(DerivedMesh *dm, Object *ob)
 {
-	dm->totmat = ob->totcol + 1; /* materials start from 1, default material is 0 */
-	dm->mat = *give_matarar(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);
+
+	dm->mat = MEM_callocN (totmat * sizeof(*dm->mat), "DerivedMesh.mat");
+
+	for (i = 1; i < totmat; i++) {
+		dm->mat[i] = give_current_material(ob, i);
+	}
 }




More information about the Bf-blender-cvs mailing list