[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [40940] trunk/blender/source/blender: fix for crash caused by invalid active material index while editing text.

Campbell Barton ideasman42 at gmail.com
Wed Oct 12 01:08:18 CEST 2011


Revision: 40940
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40940
Author:   campbellbarton
Date:     2011-10-11 23:08:17 +0000 (Tue, 11 Oct 2011)
Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/font.c
    trunk/blender/source/blender/blenkernel/intern/material.c
    trunk/blender/source/blender/editors/curve/editfont.c

Modified: trunk/blender/source/blender/blenkernel/intern/font.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/font.c	2011-10-11 17:30:08 UTC (rev 40939)
+++ trunk/blender/source/blender/blenkernel/intern/font.c	2011-10-11 23:08:17 UTC (rev 40940)
@@ -546,7 +546,7 @@
 			nu2->knotsu = nu2->knotsv = NULL;
 			nu2->flag= CU_SMOOTH;
 			nu2->charidx = charidx;
-			if (info->mat_nr) {
+			if (info->mat_nr > 0) {
 				nu2->mat_nr= info->mat_nr-1;
 			}
 			else {

Modified: trunk/blender/source/blender/blenkernel/intern/material.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/material.c	2011-10-11 17:30:08 UTC (rev 40939)
+++ trunk/blender/source/blender/blenkernel/intern/material.c	2011-10-11 23:08:17 UTC (rev 40940)
@@ -1105,8 +1105,17 @@
 	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 @@
 	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; a<ob->totcol; a++)
 		(*matarar)[a-1]= (*matarar)[a];

Modified: trunk/blender/source/blender/editors/curve/editfont.c
===================================================================
--- trunk/blender/source/blender/editors/curve/editfont.c	2011-10-11 17:30:08 UTC (rev 40939)
+++ trunk/blender/source/blender/editors/curve/editfont.c	2011-10-11 23:08:17 UTC (rev 40940)
@@ -264,9 +264,16 @@
 	EditFont *ef= cu->editfont;
 	cu->curinfo = ef->textbufinfo[cu->pos?cu->pos-1:0];
 	
-	if(obedit->totcol>0)
+	if(obedit->totcol > 0) {
 		obedit->actcol= ef->textbufinfo[cu->pos?cu->pos-1:0].mat_nr;
 
+		/* since this array is calloc'd, it can be 0 even though we try ensure
+		 * (mat_nr > 0) almost everywhere */
+		if (obedit->actcol < 1) {
+			obedit->actcol= 1;
+		}
+	}
+
 	if(mode == FO_EDIT)
 		update_string(cu);
 




More information about the Bf-blender-cvs mailing list