From 4573120399b5888c640edff8b6a9eadf91662396 Mon Sep 17 00:00:00 2001 From: Matt Ebb Date: Tue, 10 Nov 2009 06:29:10 +0000 Subject: Fix for [#19847] Joined meshes fail to render Join function was accessing invalid memory for material indices when no materials were originally present on the joining objects --- source/blender/editors/mesh/meshtools.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'source') diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 8bd8629a595..18125207eca 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -123,7 +123,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) KeyBlock *kb, *okb, *kbn; float imat[4][4], cmat[4][4], *fp1, *fp2, curpos; int a, b, totcol, totmat=0, totedge=0, totvert=0, totface=0, ok=0; - int vertofs, *matmap; + int vertofs, *matmap=NULL; int i, j, index, haskey=0, edgeofs, faceofs; bDeformGroup *dg, *odg; MDeformVert *dvert; @@ -168,7 +168,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) /* new material indices and material array */ matar= MEM_callocN(sizeof(void*)*totmat, "join_mesh matar"); - matmap= MEM_callocN(sizeof(int)*totmat, "join_mesh matmap"); + if (totmat) matmap= MEM_callocN(sizeof(int)*totmat, "join_mesh matmap"); totcol= ob->totcol; /* obact materials in new main array, is nicer start! */ @@ -435,7 +435,10 @@ int join_mesh_exec(bContext *C, wmOperator *op) mface->v3+= vertofs; if(mface->v4) mface->v4+= vertofs; - mface->mat_nr= matmap[(int)mface->mat_nr]; + if (matmap) + mface->mat_nr= matmap[(int)mface->mat_nr]; + else + mface->mat_nr= 0; } faceofs += me->totface; @@ -508,7 +511,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) ob->totcol= me->totcol= totcol; ob->colbits= 0; - MEM_freeN(matmap); + if (matmap) MEM_freeN(matmap); /* other mesh users */ test_object_materials((ID *)me); -- cgit v1.2.3