When using CTRL+L for materials, you can end up with non-existing material
indices in faces. The drawing code then was still happily drawing the old
situation (or something random, its a static array).
This commit checks the maximum amount of materials on an object, and draws
the last available material for a non-existing index. It uses an ugly
global yes, but this code is bad anyway. :)
// Materials start counting at # one....
#define MAXMATBUF (MAXMAT + 1)
static float matbuf[MAXMATBUF][2][4];
+static int totmat_gl= 0;
static int set_gl_material(int nr)
{
static int last_gl_matnr= -1;
static int last_ret_val= 1;
+ /* prevent index to use un-initialized array items */
+ if(nr>totmat_gl) nr= totmat_gl;
+
if(nr<0) {
last_gl_matnr= -1;
last_ret_val= 1;
}
}
+ totmat_gl= ob->totcol;
set_gl_material(-1); // signal for static variable
return has_alpha;
}
matar2= MEM_dupallocN(*obmatarar);
}
else {
- matar1= matar2= 0;
+ matar1= matar2= NULL;
}
/* remove links from obt */