Revision: 42480
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42480
Author:   campbellbarton
Date:     2011-12-07 09:13:15 +0000 (Wed, 07 Dec 2011)
Log Message:
-----------
fix for NULL pointer free and add in some checks, while looking into bug 
[#29521],
add asserts so we know if an invalid active index is ever set.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/object/object_vgroup.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_vertex.c
    trunk/blender/source/blender/editors/space_outliner/outliner_select.c

Modified: trunk/blender/source/blender/editors/object/object_vgroup.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_vgroup.c 2011-12-07 
08:03:52 UTC (rev 42479)
+++ trunk/blender/source/blender/editors/object/object_vgroup.c 2011-12-07 
09:13:15 UTC (rev 42480)
@@ -1608,22 +1608,38 @@
                         sel, sel_mirr,                                        \
                         flip_map, flip_map_len,                               \
                         mirror_weights, flip_vgroups,                         \
-                        all_vgroups, act_vgroup                               \
+                        all_vgroups, def_nr                                   \
                         )
 
        EditVert *eve, *eve_mirr;
        MDeformVert *dvert, *dvert_mirr;
        short sel, sel_mirr;
        int     *flip_map, flip_map_len;
-       const int act_vgroup= ob->actdef > 0 ? ob->actdef-1 : 0;
+       const int def_nr= ob->actdef-1;
 
-       if(mirror_weights==0 && flip_vgroups==0)
+       if ( (mirror_weights==0 && flip_vgroups==0) ||
+            (BLI_findlink(&ob->defbase, def_nr) == NULL) )
+       {
                return;
+       }
 
-       flip_map= all_vgroups ?
-                   defgroup_flip_map(ob, &flip_map_len, FALSE) :
-                   defgroup_flip_map_single(ob, &flip_map_len, FALSE, 
act_vgroup);
+       if (flip_vgroups) {
+               flip_map= all_vgroups ?
+                                       defgroup_flip_map(ob, &flip_map_len, 
FALSE) :
+                                       defgroup_flip_map_single(ob, 
&flip_map_len, FALSE, def_nr);
 
+               BLI_assert(flip_map != NULL);
+
+               if (flip_map == NULL) {
+                       /* something went wrong!, possibly no groups */
+                       return;
+               }
+       }
+       else {
+               flip_map= NULL;
+               flip_map_len= 0;
+       }
+
        /* only the active group */
        if(ob->type == OB_MESH) {
                Mesh *me= ob->data;
@@ -1631,8 +1647,7 @@
 
                if (em) {
                        if(!CustomData_has_layer(&em->vdata, CD_MDEFORMVERT)) {
-                               MEM_freeN(flip_map);
-                               return;
+                               goto cleanup;
                        }
 
                        EM_cache_x_mirror_vert(ob, em);
@@ -1654,7 +1669,6 @@
                                        eve->tmp.v= eve_mirr->tmp.v= NULL;
                                }
                        }
-
                        BKE_mesh_end_editmesh(me, em);
                }
                else {
@@ -1664,8 +1678,7 @@
                        const int use_vert_sel= (me->editflag & 
ME_EDIT_VERT_SEL) != 0;
 
                        if (me->dvert == NULL) {
-                               MEM_freeN(flip_map);
-                               return;
+                               goto cleanup;
                        }
 
                        if (!use_vert_sel) {
@@ -1712,8 +1725,7 @@
                if(lt->editlatt) lt= lt->editlatt->latt;
 
                if(lt->pntsu == 1 || lt->dvert == NULL) {
-                       MEM_freeN(flip_map);
-                       return;
+                       goto cleanup;
                }
 
                /* unlike editmesh we know that by only looping over the first 
hald of
@@ -1749,9 +1761,11 @@
                }
        }
 
-       MEM_freeN(flip_map);
+cleanup:
+       if (flip_map) MEM_freeN(flip_map);
 
 #undef VGROUP_MIRR_OP
+
 }
 
 static void vgroup_remap_update_users(Object *ob, int *map)
@@ -2733,6 +2747,7 @@
        int nr= RNA_enum_get(op->ptr, "group");
 
        ob->actdef= nr+1;
+       BLI_assert(ob->actdef >= 0);
 
        DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
        WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob);
@@ -2811,7 +2826,7 @@
        MDeformVert *dvert= NULL;
        bDeformGroup *def;
        int def_tot = BLI_countlist(&ob->defbase);
-       int *sort_map_update= MEM_mallocN(MAX_VGROUP_NAME * sizeof(int) * 
def_tot + 1, "sort vgroups"); /* needs a dummy index at the start*/
+       int *sort_map_update= MEM_mallocN(sizeof(int) * (def_tot + 1), "sort 
vgroups"); /* needs a dummy index at the start*/
        int *sort_map= sort_map_update + 1;
        char *name;
        int i;
@@ -2820,6 +2835,8 @@
        for(def= ob->defbase.first, i=0; def; def=def->next, i++){
                sort_map[i]= BLI_findstringindex(&ob->defbase, name, 
offsetof(bDeformGroup, name));
                name += MAX_VGROUP_NAME;
+
+               BLI_assert(sort_map[i] != -1);
        }
 
        if(ob->mode == OB_MODE_EDIT) {
@@ -2861,6 +2878,7 @@
        vgroup_remap_update_users(ob, sort_map_update);
 
        ob->actdef= sort_map_update[ob->actdef];
+       BLI_assert(ob->actdef >= 0);
        
        MEM_freeN(sort_map_update);
 

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_vertex.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_vertex.c    
2011-12-07 08:03:52 UTC (rev 42479)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_vertex.c    
2011-12-07 09:13:15 UTC (rev 42480)
@@ -1022,6 +1022,7 @@
        view3d_set_viewcontext(C, &vc);
 
        vc.obact->actdef= type + 1;
+       BLI_assert(vc.obact->actdef >= 0);
 
        DAG_id_tag_update(&vc.obact->id, OB_RECALC_DATA);
        WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, vc.obact);
@@ -1879,10 +1880,13 @@
 
                                if(pchan) {
                                        bDeformGroup *dg= 
defgroup_find_name(ob, pchan->name);
-                                       if(dg==NULL)
+                                       if(dg==NULL) {
                                                dg= ED_vgroup_add_name(ob, 
pchan->name);        /* sets actdef */
-                                       else
+                                       }
+                                       else {
                                                ob->actdef= 1 + 
defgroup_find_index(ob, dg);
+                                               BLI_assert(ob->actdef >= 0);
+                                       }
                                }
                        }
                }
@@ -1954,7 +1958,7 @@
        wpi.defbase_tot=        wpd->defbase_tot;
        wpi.defbase_sel=        MEM_mallocN(wpi.defbase_tot*sizeof(char), 
"wpi.defbase_sel");
        wpi.defbase_tot_sel=    get_selected_defgroups(ob, wpi.defbase_sel, 
wpi.defbase_tot);
-       if(wpi.defbase_tot_sel == 0 && ob->actdef) wpi.defbase_tot_sel = 1;
+       if(wpi.defbase_tot_sel == 0 && ob->actdef > 0) wpi.defbase_tot_sel = 1;
        wpi.defbase_tot_unsel=  wpi.defbase_tot - wpi.defbase_tot_sel;
        wpi.vgroup_mirror=      wpd->vgroup_mirror;
        wpi.lock_flags=         wpd->lock_flags;

Modified: trunk/blender/source/blender/editors/space_outliner/outliner_select.c
===================================================================
--- trunk/blender/source/blender/editors/space_outliner/outliner_select.c       
2011-12-07 08:03:52 UTC (rev 42479)
+++ trunk/blender/source/blender/editors/space_outliner/outliner_select.c       
2011-12-07 09:13:15 UTC (rev 42480)
@@ -397,6 +397,8 @@
        ob= (Object *)tselem->id;
        if(set) {
                ob->actdef= te->index+1;
+               BLI_assert(ob->actdef >= 0);
+
                DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
                WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob);
        }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to