Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-10-27 11:54:32 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-10-27 11:54:32 +0400
commit99075b35ed3e5f42f4e652f68b9a5612b54c4cde (patch)
tree0b0f8b8578881e1cbcd3b4e8acd5ae0eae747934
parentc936c61bace7892950c33f7aa93a92fc719dfca9 (diff)
fix [#29044] applying mirror modifier causes crash; something with vertex groups?
-rw-r--r--source/blender/blenkernel/BKE_deform.h6
-rw-r--r--source/blender/blenkernel/intern/deform.c34
-rw-r--r--source/blender/editors/object/object_vgroup.c14
-rw-r--r--source/blender/editors/space_view3d/view3d_buttons.c6
-rw-r--r--source/blender/modifiers/intern/MOD_mirror.c6
5 files changed, 35 insertions, 31 deletions
diff --git a/source/blender/blenkernel/BKE_deform.h b/source/blender/blenkernel/BKE_deform.h
index 15d3c86c315..84a6517fd52 100644
--- a/source/blender/blenkernel/BKE_deform.h
+++ b/source/blender/blenkernel/BKE_deform.h
@@ -44,7 +44,7 @@ void defgroup_copy_list(struct ListBase *lb1, struct ListBase *lb2);
struct bDeformGroup *defgroup_duplicate(struct bDeformGroup *ingroup);
struct bDeformGroup *defgroup_find_name(struct Object *ob, const char *name);
int defgroup_find_index(struct Object *ob, struct bDeformGroup *dg);
-int *defgroup_flip_map(struct Object *ob, int use_default);
+int *defgroup_flip_map(struct Object *ob, int *flip_map_len, int use_default);
int defgroup_flip_index(struct Object *ob, int index, int use_default);
int defgroup_name_index(struct Object *ob, const char *name);
void defgroup_unique_name(struct bDeformGroup *dg, struct Object *ob);
@@ -57,9 +57,9 @@ float defvert_array_find_weight_safe(const struct MDeformVert *dvert, int index
void defvert_copy(struct MDeformVert *dvert_r, const struct MDeformVert *dvert);
void defvert_sync(struct MDeformVert *dvert_r, const struct MDeformVert *dvert, int use_verify);
-void defvert_sync_mapped(struct MDeformVert *dvert_r, const struct MDeformVert *dvert, const int *flip_map, int use_verify);
+void defvert_sync_mapped(struct MDeformVert *dvert_r, const struct MDeformVert *dvert, const int *flip_map, const int flip_map_len, int use_verify);
void defvert_remap (struct MDeformVert *dvert, int *map);
-void defvert_flip(struct MDeformVert *dvert, const int *flip_map);
+void defvert_flip(struct MDeformVert *dvert, const int *flip_map, const int flip_map_len);
void defvert_normalize(struct MDeformVert *dvert);
/* utility function, note that 32 chars is the maximum string length since its only
diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c
index 0f6828cc358..b8f5d79ea0d 100644
--- a/source/blender/blenkernel/intern/deform.c
+++ b/source/blender/blenkernel/intern/deform.c
@@ -114,18 +114,20 @@ void defvert_sync (MDeformVert *dvert_r, const MDeformVert *dvert, int use_verif
}
/* be sure all flip_map values are valid */
-void defvert_sync_mapped (MDeformVert *dvert_r, const MDeformVert *dvert, const int *flip_map, int use_verify)
+void defvert_sync_mapped (MDeformVert *dvert_r, const MDeformVert *dvert, const int *flip_map, const int flip_map_len, const int use_verify)
{
- if(dvert->totweight && dvert_r->totweight) {
+ if (dvert->totweight && dvert_r->totweight) {
int i;
MDeformWeight *dw;
- for(i=0, dw=dvert->dw; i < dvert->totweight; i++, dw++) {
- MDeformWeight *dw_r;
- if(use_verify) dw_r= defvert_find_index(dvert_r, flip_map[dw->def_nr]);
- else dw_r= defvert_verify_index(dvert_r, flip_map[dw->def_nr]);
-
- if(dw_r) {
- dw_r->weight= dw->weight;
+ for (i=0, dw=dvert->dw; i < dvert->totweight; i++, dw++) {
+ if (dw->def_nr < flip_map_len) {
+ MDeformWeight *dw_r;
+ if(use_verify) dw_r= defvert_find_index(dvert_r, flip_map[dw->def_nr]);
+ else dw_r= defvert_verify_index(dvert_r, flip_map[dw->def_nr]);
+
+ if(dw_r) {
+ dw_r->weight= dw->weight;
+ }
}
}
}
@@ -163,14 +165,16 @@ void defvert_normalize (MDeformVert *dvert)
}
}
-void defvert_flip (MDeformVert *dvert, const int *flip_map)
+void defvert_flip (MDeformVert *dvert, const int *flip_map, const int flip_map_len)
{
MDeformWeight *dw;
int i;
- for(dw= dvert->dw, i=0; i<dvert->totweight; dw++, i++)
- if(flip_map[dw->def_nr] >= 0)
+ for(dw= dvert->dw, i=0; i<dvert->totweight; dw++, i++) {
+ if((dw->def_nr < flip_map_len) && (flip_map[dw->def_nr] >= 0)) {
dw->def_nr= flip_map[dw->def_nr];
+ }
+ }
}
@@ -250,17 +254,17 @@ int defgroup_find_index (Object *ob, bDeformGroup *dg)
}
/* note, must be freed */
-int *defgroup_flip_map(Object *ob, int use_default)
+int *defgroup_flip_map(Object *ob, int *flip_map_len, int use_default)
{
bDeformGroup *dg;
- int totdg= BLI_countlist(&ob->defbase);
+ int totdg= *flip_map_len= BLI_countlist(&ob->defbase);
if(totdg==0) {
return NULL;
}
else {
char name[sizeof(dg->name)];
- int i, flip_num, *map= MEM_mallocN(totdg * sizeof(int), "get_defgroup_flip_map");
+ int i, flip_num, *map= MEM_mallocN(totdg * sizeof(int), __func__);
memset(map, -1, totdg * sizeof(int));
diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c
index 378e4a4f314..d4ee68f8b72 100644
--- a/source/blender/editors/object/object_vgroup.c
+++ b/source/blender/editors/object/object_vgroup.c
@@ -1527,7 +1527,7 @@ static void vgroup_clean_all(Object *ob, float eul, int keep_single)
static void dvert_mirror_op(MDeformVert *dvert, MDeformVert *dvert_mirr,
const char sel, const char sel_mirr,
- const int *flip_map,
+ const int *flip_map, const int flip_map_len,
const short mirror_weights, const short flip_vgroups)
{
BLI_assert(sel || sel_mirr);
@@ -1537,8 +1537,8 @@ static void dvert_mirror_op(MDeformVert *dvert, MDeformVert *dvert_mirr,
if(mirror_weights)
SWAP(MDeformVert, *dvert, *dvert_mirr);
if(flip_vgroups) {
- defvert_flip(dvert, flip_map);
- defvert_flip(dvert_mirr, flip_map);
+ defvert_flip(dvert, flip_map, flip_map_len);
+ defvert_flip(dvert_mirr, flip_map, flip_map_len);
}
}
else {
@@ -1550,24 +1550,24 @@ static void dvert_mirror_op(MDeformVert *dvert, MDeformVert *dvert_mirr,
if(mirror_weights)
defvert_copy(dvert, dvert_mirr);
if(flip_vgroups) {
- defvert_flip(dvert, flip_map);
+ defvert_flip(dvert, flip_map, flip_map_len);
}
}
}
void ED_vgroup_mirror(Object *ob, const short mirror_weights, const short flip_vgroups)
{
-#define VGROUP_MIRR_OP dvert_mirror_op(dvert, dvert_mirr, sel, sel_mirr, flip_map, mirror_weights, flip_vgroups)
+#define VGROUP_MIRR_OP dvert_mirror_op(dvert, dvert_mirr, sel, sel_mirr, flip_map, flip_map_len, mirror_weights, flip_vgroups)
EditVert *eve, *eve_mirr;
MDeformVert *dvert, *dvert_mirr;
short sel, sel_mirr;
- int *flip_map;
+ int *flip_map, flip_map_len;
if(mirror_weights==0 && flip_vgroups==0)
return;
- flip_map= defgroup_flip_map(ob, 0);
+ flip_map= defgroup_flip_map(ob, &flip_map_len, FALSE);
/* only the active group */
if(ob->type == OB_MESH) {
diff --git a/source/blender/editors/space_view3d/view3d_buttons.c b/source/blender/editors/space_view3d/view3d_buttons.c
index 5e0a32c41c8..63b0f68f158 100644
--- a/source/blender/editors/space_view3d/view3d_buttons.c
+++ b/source/blender/editors/space_view3d/view3d_buttons.c
@@ -613,9 +613,9 @@ static void editvert_mirror_update(Object *ob, EditVert *eve, int def_nr, int in
if(dvert_dst) {
if(def_nr == -1) {
/* all vgroups, add groups where neded */
-
- int *flip_map= defgroup_flip_map(ob, 1);
- defvert_sync_mapped(dvert_dst, dvert_src, flip_map, 1);
+ int flip_map_len;
+ int *flip_map= defgroup_flip_map(ob, &flip_map_len, TRUE);
+ defvert_sync_mapped(dvert_dst, dvert_src, flip_map, flip_map_len, TRUE);
MEM_freeN(flip_map);
}
else {
diff --git a/source/blender/modifiers/intern/MOD_mirror.c b/source/blender/modifiers/intern/MOD_mirror.c
index f551f0f5e7a..b36850da786 100644
--- a/source/blender/modifiers/intern/MOD_mirror.c
+++ b/source/blender/modifiers/intern/MOD_mirror.c
@@ -108,7 +108,7 @@ static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd,
int maxVerts = dm->getNumVerts(dm);
int maxEdges = dm->getNumEdges(dm);
int maxFaces = dm->getNumFaces(dm);
- int *flip_map= NULL;
+ int *flip_map= NULL, flip_map_len= 0;
int do_vgroup_mirr= (mmd->flag & MOD_MIR_VGROUP);
int (*indexMap)[2];
float mtx[4][4], imtx[4][4];
@@ -121,7 +121,7 @@ static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd,
if (do_vgroup_mirr) {
- flip_map= defgroup_flip_map(ob, 0);
+ flip_map= defgroup_flip_map(ob, &flip_map_len, FALSE);
if(flip_map == NULL)
do_vgroup_mirr= 0;
}
@@ -187,7 +187,7 @@ static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd,
if (do_vgroup_mirr) {
MDeformVert *dvert= DM_get_vert_data(result, numVerts, CD_MDEFORMVERT);
if(dvert) {
- defvert_flip(dvert, flip_map);
+ defvert_flip(dvert, flip_map, flip_map_len);
}
}