Revision: 40144
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40144
Author:   campbellbarton
Date:     2011-09-12 02:23:30 +0000 (Mon, 12 Sep 2011)
Log Message:
-----------
revert own commit r40051, mesh and object pointers are needed for undo, this 
commit caused bug [#28625] Separate crash bug.

also added a safety check for the crash, even though reverting fixes.
bmesh_to_mesh_exec() could set me->mface array to NULL but leave me->totface 
when notellelation=1, which is likely to give trouble elsewhere.

Revision Links:
--------------
    
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40051

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/blenkernel/BKE_mesh.h
    branches/bmesh/blender/source/blender/blenkernel/intern/mesh.c
    branches/bmesh/blender/source/blender/bmesh/bmesh.h
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_inline.c
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c
    branches/bmesh/blender/source/blender/bmesh/operators/mesh_conv.c
    branches/bmesh/blender/source/blender/editors/mesh/bmesh_tools.c
    branches/bmesh/blender/source/blender/editors/mesh/bmeshutils.c

Modified: branches/bmesh/blender/source/blender/blenkernel/BKE_mesh.h
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/BKE_mesh.h 2011-09-12 
01:43:20 UTC (rev 40143)
+++ branches/bmesh/blender/source/blender/blenkernel/BKE_mesh.h 2011-09-12 
02:23:30 UTC (rev 40144)
@@ -61,7 +61,7 @@
 extern "C" {
 #endif
 
-struct BMesh *BKE_mesh_to_bmesh(struct Object *ob);
+struct BMesh *BKE_mesh_to_bmesh(struct Mesh *me, struct Object *ob);
 
 /*
   this function recreates a tesselation.

Modified: branches/bmesh/blender/source/blender/blenkernel/intern/mesh.c
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/intern/mesh.c      
2011-09-12 01:43:20 UTC (rev 40143)
+++ branches/bmesh/blender/source/blender/blenkernel/intern/mesh.c      
2011-09-12 02:23:30 UTC (rev 40144)
@@ -569,14 +569,14 @@
        return men;
 }
 
-BMesh *BKE_mesh_to_bmesh(Object *ob)
+BMesh *BKE_mesh_to_bmesh(Mesh *me, Object *ob)
 {
        BMesh *bm;
        int allocsize[4] = {512,512,2048,512};
 
        bm = BM_Make_Mesh(ob, allocsize);
 
-       BMO_CallOpf(bm, "mesh_to_bmesh set_shapekey=%i", 1);
+       BMO_CallOpf(bm, "mesh_to_bmesh mesh=%p object=%p set_shapekey=%i", me, 
ob, 1);
 
        return bm;
 }

Modified: branches/bmesh/blender/source/blender/bmesh/bmesh.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/bmesh.h 2011-09-12 01:43:20 UTC 
(rev 40143)
+++ branches/bmesh/blender/source/blender/bmesh/bmesh.h 2011-09-12 02:23:30 UTC 
(rev 40144)
@@ -143,7 +143,7 @@
 struct BMFace *BM_Make_Ngon ( struct BMesh *bm, struct BMVert *v1, struct 
BMVert *v2, struct BMEdge **edges, int len, int nodouble );
 
 /*stuff for dealing with header flags*/
-BM_INLINE int BM_TestHFlag(const void *element, const int flag);
+BM_INLINE int BM_TestHFlag(void *element, const int flag);
 
 /*stuff for dealing with header flags*/
 BM_INLINE void BM_SetHFlag(void *element, const int flag);

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_inline.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_inline.c   
2011-09-12 01:43:20 UTC (rev 40143)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_inline.c   
2011-09-12 02:23:30 UTC (rev 40144)
@@ -3,9 +3,10 @@
 
 #include "bmesh.h"
 
-BM_INLINE int BM_TestHFlag(const void *element, const int flag)
+BM_INLINE int BM_TestHFlag(void *element, const int flag)
 {
-       return ((BMHeader *)element)->flag & flag;
+       BMHeader *e = element;
+       return e->flag & flag;
 }
 
 BM_INLINE void BM_SetHFlag(void *element, const int flag)

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c        
2011-09-12 01:43:20 UTC (rev 40143)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c        
2011-09-12 02:23:30 UTC (rev 40144)
@@ -497,6 +497,7 @@
 static BMOpDefine def_object_load_bmesh = {
        "object_load_bmesh",
        {{BMOP_OPSLOT_PNT, "scene"},
+       {BMOP_OPSLOT_PNT, "object"},
        {0, /*null-terminating sentinel*/}},
        object_load_bmesh_exec,
        0,
@@ -510,7 +511,9 @@
 */
 static BMOpDefine def_bmesh_to_mesh = {
        "bmesh_to_mesh",
-    {{BMOP_OPSLOT_INT, "notesselation"}, //don't calculate mfaces
+       {{BMOP_OPSLOT_PNT, "mesh"}, //pointer to a mesh structure to fill in
+        {BMOP_OPSLOT_PNT, "object"}, //pointer to an object structure
+        {BMOP_OPSLOT_INT, "notesselation"}, //don't calculate mfaces
         {0, /*null-terminating sentinel*/}},
        bmesh_to_mesh_exec,
        0,
@@ -524,7 +527,9 @@
 */
 static BMOpDefine def_mesh_to_bmesh = {
        "mesh_to_bmesh",
-    {{BMOP_OPSLOT_INT, "set_shapekey"}, //load active shapekey coordinates 
into verts
+       {{BMOP_OPSLOT_PNT, "mesh"}, //pointer to a Mesh structure
+        {BMOP_OPSLOT_PNT, "object"}, //pointer to an Object structure
+        {BMOP_OPSLOT_INT, "set_shapekey"}, //load active shapekey coordinates 
into verts
         {0, /*null-terminating sentinel*/}},
        mesh_to_bmesh_exec,
        0

Modified: branches/bmesh/blender/source/blender/bmesh/operators/mesh_conv.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/operators/mesh_conv.c   
2011-09-12 01:43:20 UTC (rev 40143)
+++ branches/bmesh/blender/source/blender/bmesh/operators/mesh_conv.c   
2011-09-12 02:23:30 UTC (rev 40144)
@@ -44,8 +44,8 @@
 */
 
 void mesh_to_bmesh_exec(BMesh *bm, BMOperator *op) {
-       Object *ob = bm->ob;
-       Mesh *me = ob->data;
+       Object *ob = BMO_Get_Pnt(op, "object");
+       Mesh *me = BMO_Get_Pnt(op, "mesh");
        MVert *mvert;
        BLI_array_declare(verts);
        MEdge *medge;
@@ -347,9 +347,12 @@
        }
 }
 
-void object_load_bmesh_exec(BMesh *bm, BMOperator *UNUSED(op))
-{
-       BMO_CallOpf(bm, "bmesh_to_mesh");
+void object_load_bmesh_exec(BMesh *bm, BMOperator *op) {
+       Object *ob = BMO_Get_Pnt(op, "object");
+       /* Scene *scene = BMO_Get_Pnt(op, "scene"); */
+       Mesh *me = ob->data;
+
+       BMO_CallOpf(bm, "bmesh_to_mesh mesh=%p object=%p", me, ob);
 }
 
 
@@ -393,8 +396,8 @@
 }
 
 void bmesh_to_mesh_exec(BMesh *bm, BMOperator *op) {
-       Object *ob = bm->ob;
-       Mesh *me = ob->data;
+       Mesh *me = BMO_Get_Pnt(op, "mesh");
+       /* Object *ob = BMO_Get_Pnt(op, "object"); */
        MLoop *mloop;
        KeyBlock *block;
        MPoly *mpoly;
@@ -405,8 +408,7 @@
        BMEdge *e;
        BMLoop *l;
        BMFace *f;
-       BMIter iter, liter;
-       float *facenors = NULL;
+       BMIter iter, liter; float *facenors = NULL;
        int i, j, *keyi, ototvert, totloop, totface, numTex, numCol;
        int dotess = !BMO_Get_Int(op, "notesselation");
 
@@ -456,6 +458,10 @@
        me->totedge= bm->totedge;
        me->totloop= totloop;
        me->totpoly= bm->totface;
+       /* will be overwritten with a valid value if 'dotess' is set, otherwise 
we
+        * end up with 'me->totface' and me->mface == NULL which can crash 
[#28625]
+        */
+       me->totface= 0;
 
        CustomData_copy(&bm->vdata, &me->vdata, CD_MASK_MESH, CD_CALLOC, 
me->totvert);
        CustomData_copy(&bm->edata, &me->edata, CD_MASK_MESH, CD_CALLOC, 
me->totedge);

Modified: branches/bmesh/blender/source/blender/editors/mesh/bmesh_tools.c
===================================================================
--- branches/bmesh/blender/source/blender/editors/mesh/bmesh_tools.c    
2011-09-12 01:43:20 UTC (rev 40143)
+++ branches/bmesh/blender/source/blender/editors/mesh/bmesh_tools.c    
2011-09-12 02:23:30 UTC (rev 40144)
@@ -3571,7 +3571,7 @@
        EDBM_CallOpf(em, wmop, "del geom=%hvef context=%i", BM_SELECT, 
DEL_VERTS);
        
        BM_Compute_Normals(bmnew);
-       BMO_CallOpf(bmnew, "bmesh_to_mesh");
+       BMO_CallOpf(bmnew, "bmesh_to_mesh mesh=%p object=%p", 
basenew->object->data, basenew->object);
                
        BM_Free_Mesh(bmnew);
        ((Mesh*)basenew->object->data)->edit_btmesh = NULL;

Modified: branches/bmesh/blender/source/blender/editors/mesh/bmeshutils.c
===================================================================
--- branches/bmesh/blender/source/blender/editors/mesh/bmeshutils.c     
2011-09-12 01:43:20 UTC (rev 40143)
+++ branches/bmesh/blender/source/blender/editors/mesh/bmeshutils.c     
2011-09-12 02:23:30 UTC (rev 40144)
@@ -270,9 +270,9 @@
                printf("yeek!! bmesh conversion issue! may lose lots of 
geometry!\n");
                
                /*BMESH_TODO need to write smarter code here*/
-               bm = BKE_mesh_to_bmesh(ob);
+               bm = BKE_mesh_to_bmesh(me, ob);
        } else {
-               bm = BKE_mesh_to_bmesh(ob);
+               bm = BKE_mesh_to_bmesh(me, ob);
        }
 
        me->edit_btmesh = BMEdit_Create(bm);
@@ -286,7 +286,7 @@
        Mesh *me = ob->data;
        BMesh *bm = me->edit_btmesh->bm;
 
-       BMO_CallOpf(bm, "object_load_bmesh scene=%p", scene);
+       BMO_CallOpf(bm, "object_load_bmesh scene=%p object=%p", scene, ob);
 }
 
 void EDBM_FreeEditBMesh(BMEditMesh *tm)
@@ -580,7 +580,7 @@
          BMEdit_RecalcTesselation throughout the code.*/
        BMEdit_RecalcTesselation(em);
 
-       BMO_CallOpf(em->bm, "bmesh_to_mesh notesselation=%i", 1);
+       BMO_CallOpf(em->bm, "bmesh_to_mesh mesh=%p notesselation=%i", me, 1);
        me->selectmode = em->selectmode;
 
        return me;
@@ -600,7 +600,7 @@
        BMEdit_Free(em);
 
        bm = BM_Make_Mesh(ob, allocsize);
-       BMO_CallOpf(bm, "mesh_to_bmesh set_shapekey=%i", 0);
+       BMO_CallOpf(bm, "mesh_to_bmesh mesh=%p object=%p set_shapekey=%i", me, 
ob, 0);
 
        em2 = BMEdit_Create(bm);
        *em = *em2;

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

Reply via email to