diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-06-07 22:04:03 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-06-07 22:04:03 +0400 |
commit | 299602b360291377e190a7d96c449e03693f05a2 (patch) | |
tree | 948bebf7d0573d64640788c9ba6f5b65a3baa09e | |
parent | d16c1f36653196d32f9915b4ba633a9c4c6569d0 (diff) |
fix for vertex group copy to selected
- was using un-initialized stack memory if the source / target object had no vertex group.
- if the target object had no vertex groups it would fails silently (not a bug but not very good functionality)
- added an error message if any copying fails.
-rw-r--r-- | source/blender/editors/include/ED_mesh.h | 2 | ||||
-rw-r--r-- | source/blender/editors/object/object_vgroup.c | 43 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_conversions.c | 1 |
3 files changed, 35 insertions, 11 deletions
diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h index ade69a00ff8..8bb77ad43a0 100644 --- a/source/blender/editors/include/ED_mesh.h +++ b/source/blender/editors/include/ED_mesh.h @@ -206,7 +206,7 @@ struct bDeformGroup *ED_vgroup_add(struct Object *ob); struct bDeformGroup *ED_vgroup_add_name(struct Object *ob, const char *name); void ED_vgroup_delete(struct Object *ob, struct bDeformGroup *defgroup); void ED_vgroup_select_by_name(struct Object *ob, const char *name); -void ED_vgroup_data_create(struct ID *id); +int ED_vgroup_data_create(struct ID *id); int ED_vgroup_give_array(struct ID *id, struct MDeformVert **dvert_arr, int *dvert_tot); int ED_vgroup_copy_array(struct Object *ob, struct Object *ob_from); void ED_vgroup_mirror(struct Object *ob, const short mirror_weights, const short flip_vgroups); diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 072c08c7ec0..fca21cdcf64 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -77,6 +77,7 @@ static void vgroup_remap_update_users(Object *ob, int *map); static void vgroup_delete_edit_mode(Object *ob, bDeformGroup *defgroup); static void vgroup_delete_object_mode(Object *ob, bDeformGroup *dg); +static void vgroup_delete_all(Object *ob); static Lattice *vgroup_edit_lattice(Object *ob) { @@ -138,22 +139,30 @@ void ED_vgroup_delete(Object *ob, bDeformGroup *defgroup) vgroup_delete_object_mode(ob, dg); } -void ED_vgroup_data_create(ID *id) +int ED_vgroup_data_create(ID *id) { /* create deform verts */ if(GS(id->name)==ID_ME) { Mesh *me= (Mesh *)id; me->dvert= CustomData_add_layer(&me->vdata, CD_MDEFORMVERT, CD_CALLOC, NULL, me->totvert); + return TRUE; } else if(GS(id->name)==ID_LT) { Lattice *lt= (Lattice *)id; lt->dvert= MEM_callocN(sizeof(MDeformVert)*lt->pntsu*lt->pntsv*lt->pntsw, "lattice deformVert"); + return TRUE; + } + else { + return FALSE; } } static int ED_vgroup_give_parray(ID *id, MDeformVert ***dvert_arr, int *dvert_tot) { + *dvert_tot = 0; + *dvert_arr = NULL; + if(id) { switch(GS(id->name)) { case ID_ME: @@ -166,8 +175,6 @@ static int ED_vgroup_give_parray(ID *id, MDeformVert ***dvert_arr, int *dvert_to int i; if (!CustomData_has_layer(&em->vdata, CD_MDEFORMVERT)) { - *dvert_tot = 0; - *dvert_arr = NULL; return 0; } @@ -195,8 +202,9 @@ static int ED_vgroup_give_parray(ID *id, MDeformVert ***dvert_arr, int *dvert_to return 1; } - else + else { return 0; + } } case ID_LT: { @@ -222,8 +230,6 @@ static int ED_vgroup_give_parray(ID *id, MDeformVert ***dvert_arr, int *dvert_to } } - *dvert_arr= NULL; - *dvert_tot= 0; return 0; } @@ -265,13 +271,24 @@ int ED_vgroup_copy_array(Object *ob, Object *ob_from) int i; int totdef_from= BLI_countlist(&ob_from->defbase); int totdef= BLI_countlist(&ob->defbase); + short new_vgroup= FALSE; ED_vgroup_give_parray(ob_from->data, &dvert_array_from, &dvert_tot_from); ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot); + if((dvert_array == NULL) && (dvert_array_from != NULL) && ED_vgroup_data_create(ob->data)) { + ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot); + new_vgroup= TRUE; + } + if(ob==ob_from || dvert_tot==0 || (dvert_tot != dvert_tot_from) || dvert_array_from==NULL || dvert_array==NULL) { if (dvert_array) MEM_freeN(dvert_array); if (dvert_array_from) MEM_freeN(dvert_array_from); + + if(new_vgroup == TRUE) { + /* free the newly added vgroup since it wasn't compatible */ + vgroup_delete_all(ob->data); + } return 0; } @@ -1988,17 +2005,25 @@ void OBJECT_OT_vertex_group_copy_to_linked(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } -static int vertex_group_copy_to_selected_exec(bContext *C, wmOperator *UNUSED(op)) +static int vertex_group_copy_to_selected_exec(bContext *C, wmOperator *op) { Object *obact= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; + int change= 0; + int fail= 0; CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) { - if(obact != ob) - ED_vgroup_copy_array(ob, obact); + if(obact != ob) { + if(ED_vgroup_copy_array(ob, obact)) change++; + else fail++; + } } CTX_DATA_END; + if((change == 0 && fail == 0) || fail) { + BKE_reportf(op->reports, RPT_ERROR, "Copy to VGroups to Selected warning done %d, failed %d, object data must have matching indicies", change, fail); + } + return OPERATOR_FINISHED; } diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index 593ab7b61e9..68aa27a7b62 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -4027,7 +4027,6 @@ static void freeSeqData(TransInfo *t) if ((seq != seq_prev)) { /* check effects strips, we cant change their time */ if((seq->type & SEQ_EFFECT) && seq->seq1) { - // shuffle_seq(seqbasep, seq, t->scene); has_effect= TRUE; } else { |