diff options
author | Antony Riakiotakis <kalast@gmail.com> | 2014-04-09 19:37:54 +0400 |
---|---|---|
committer | Antony Riakiotakis <kalast@gmail.com> | 2014-04-09 19:37:54 +0400 |
commit | 1c811d96b22b0880c118aca21f151e593fc45fc2 (patch) | |
tree | 3e8833ad2195b6d98075295dd765a945c6df9ebd | |
parent | a6fb6706a88a5e39905c0874772310fafe91bdc2 (diff) |
Make material array account for mesh/object storage of materials
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index dcaf102ef01..c8862e1444c 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); + } } |