From 4750f24663cc4077861de80a38dcd21af781f30d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 11 Oct 2011 23:08:17 +0000 Subject: fix for crash caused by invalid active material index while editing text. also added some better error checking in object_remove_material_slot() so it will print an error rather then crashing if this case ever happens again. --- source/blender/blenkernel/intern/material.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'source/blender/blenkernel/intern/material.c') diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index ed9be989dbd..ebd05ab9bf8 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -1105,8 +1105,17 @@ int object_remove_material_slot(Object *ob) short *totcolp; short a, actcol; - if(ob==NULL || ob->totcol==0) return FALSE; - + if (ob==NULL || ob->totcol==0) { + return FALSE; + } + + /* this should never happen and used to crash */ + if (ob->actcol <= 0) { + printf("%s: invalid material index %d, report a bug!\n", __func__, ob->actcol); + BLI_assert(0); + return FALSE; + } + /* take a mesh/curve/mball as starting point, remove 1 index, * AND with all objects that share the ob->data * @@ -1119,10 +1128,8 @@ int object_remove_material_slot(Object *ob) if(*matarar==NULL) return FALSE; /* we delete the actcol */ - if(ob->totcol) { - mao= (*matarar)[ob->actcol-1]; - if(mao) mao->id.us--; - } + mao= (*matarar)[ob->actcol-1]; + if(mao) mao->id.us--; for(a=ob->actcol; atotcol; a++) (*matarar)[a-1]= (*matarar)[a]; -- cgit v1.2.3