=bmesh=fixed shapekey mem leak
authorJoseph Eagar <joeedh@gmail.com>
Thu, 12 May 2011 18:33:10 +0000 (18:33 +0000)
committerJoseph Eagar <joeedh@gmail.com>
Thu, 12 May 2011 18:33:10 +0000 (18:33 +0000)
source/blender/blenlib/intern/scanfill.c
source/blender/bmesh/operators/mesh_conv.c
source/blender/editors/mesh/bmeshutils.c

index 40f0176ecab46776de055e3aed62ebe38b2849f8..b5e89530e130c7eabdfb9862974d2d5f143a6bed 100644 (file)
@@ -172,8 +172,8 @@ static void *new_mem_element(int size)
                /*reset the block we're keeping*/
                BLI_addtail(&lb, first);
                memset(first->data, 0, blocksize);
-               cur = first;
-               offs = 0;
+               cur= first;
+               offs= 0;
 
                return NULL;    
        }
index efd038371e09109a359b5472ad7ff5bf2a79fe34..d9e7077c3344902eda735d5d354a9daa41d53df8 100644 (file)
@@ -78,8 +78,6 @@ void mesh_to_bmesh_exec(BMesh *bm, BMOperator *op) {
                CustomData_set_layer_name(&bm->ldata, CD_MLOOPUV, i, bm->pdata.layers[li].name);
        }
        
-       CustomData_add_layer(&bm->vdata, CD_SHAPE_KEYINDEX, CD_ASSIGN, NULL, 0);
-
        if (!CustomData_has_layer(&bm->edata, CD_CREASE))
                CustomData_add_layer(&bm->edata, CD_CREASE, CD_ASSIGN, NULL, 0);
 
@@ -96,6 +94,8 @@ void mesh_to_bmesh_exec(BMesh *bm, BMOperator *op) {
 
        actkey = ob_get_keyblock(ob);
        if(actkey && actkey->totelem == me->totvert) {
+               CustomData_add_layer(&bm->vdata, CD_SHAPE_KEYINDEX, CD_ASSIGN, NULL, 0);
+               
                /*check if we need to generate unique ids for the shapekeys.
                  this also exists in the file reading code, but is here for
                  a sanity check*/
@@ -142,12 +142,12 @@ void mesh_to_bmesh_exec(BMesh *bm, BMOperator *op) {
                /*Copy Custom Data*/
                CustomData_to_bmesh_block(&me->vdata, &bm->vdata, i, &v->head.data);
 
-               /*set shape key original index*/
-               keyi = CustomData_bmesh_get(&bm->vdata, v->head.data, CD_SHAPE_KEYINDEX);
-               *keyi = i;
-
                /*set shapekey data*/
                if (me->key) {
+                       /*set shape key original index*/
+                       keyi = CustomData_bmesh_get(&bm->vdata, v->head.data, CD_SHAPE_KEYINDEX);
+                       *keyi = i;
+                       
                        for (block=me->key->block.first, j=0; block; block=block->next, j++) {
                                float *co = CustomData_bmesh_get_n(&bm->vdata, v->head.data, 
                                                                   CD_SHAPEKEY, j);
index 23aa71f9a8e761df057b4823a0e0257426ab74c9..1aa9d0397813148aead9be42ce45c780ad1bc4cc 100644 (file)
@@ -613,6 +613,12 @@ static void undoMesh_to_editbtMesh(void *umv, void *emv, void *UNUSED(obdata))
 
 static void free_undo(void *umv)
 {
+       if (((Mesh*)umv)->key)
+       {
+               free_key(((Mesh*)umv)->key);
+               MEM_freeN(((Mesh*)umv)->key);
+       }
+       
        free_mesh(umv, 0);
        MEM_freeN(umv);
 }