Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2016-05-06 18:58:28 +0300
committerCampbell Barton <ideasman42@gmail.com>2016-05-06 19:16:21 +0300
commit9f96976e597f165bc1de34fbc950519eb8074d36 (patch)
treebaa5cae0503f508a324988c80618206c9bc0c1a1 /source/blender/blenkernel/intern/DerivedMesh.c
parentbd309603c5359443ace5af4e11d0e4bcd17e4ac6 (diff)
DerivedMesh: don't allocate a new material array each draw
Diffstat (limited to 'source/blender/blenkernel/intern/DerivedMesh.c')
-rw-r--r--source/blender/blenkernel/intern/DerivedMesh.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 57926e6a56a..1ec714ea0bb 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)