Bugfix #3961
authorTon Roosendaal <ton@blender.org>
Sat, 8 Apr 2006 15:58:49 +0000 (15:58 +0000)
committerTon Roosendaal <ton@blender.org>
Sat, 8 Apr 2006 15:58:49 +0000 (15:58 +0000)
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. :)

source/blender/src/drawobject.c
source/blender/src/editobject.c

index 88fe4dacf919f52245c2da16052c1c8cc6faa40b..b78dca9227c0a4480b1c0ea45ffd54a44d7eab0f 100644 (file)
@@ -132,12 +132,16 @@ static void draw_bounding_volume(Object *ob);
 // 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;
@@ -215,6 +219,7 @@ static int init_gl_materials(Object *ob, int check_alpha)
                }
        }
 
+       totmat_gl= ob->totcol;
        set_gl_material(-1);            // signal for static variable
        return has_alpha;
 }
index 85979160986026010b8670beb8767c34a151f8c5..9a81a1958f3e06f168321acad255d6a8623ef758 100644 (file)
@@ -3185,7 +3185,7 @@ void make_links(short event)
                                                        matar2= MEM_dupallocN(*obmatarar);
                                                }
                                                else {
-                                                       matar1= matar2= 0;
+                                                       matar1= matar2= NULL;
                                                }
                                                
                                                /* remove links from obt */