diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-03-02 22:23:08 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-03-02 22:23:08 +0400 |
commit | e9c935caa0b58d31cad19ca237a55fac8a2c6410 (patch) | |
tree | 09762f067aaa42cc908b3fc38ca398ac9f5538eb | |
parent | cc8e2d12a72fafa8758a8d46091afab23a47c271 (diff) |
fix bug [#30426] crash in bmesh python api.
if blender freed the BMesh before python was finished (on exit editmode for eg), python would attempt to access the bmesh to clear python pointers in it.
-rw-r--r-- | source/blender/bmesh/intern/bmesh_mesh.c | 7 | ||||
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_types.c | 14 |
2 files changed, 16 insertions, 5 deletions
diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c index 92ee2221b6e..944b3b434c7 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.c +++ b/source/blender/bmesh/intern/bmesh_mesh.c @@ -154,6 +154,13 @@ void BM_mesh_data_free(BMesh *bm) BLI_freelistN(&bm->selected); + if (bm->py_handle) { + extern void bpy_bm_generic_invalidate(void *self); + + bpy_bm_generic_invalidate(bm->py_handle); + bm->py_handle = NULL; + } + BMO_error_clear(bm); } diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c index 1145fbbd452..65bce912963 100644 --- a/source/blender/python/bmesh/bmesh_py_types.c +++ b/source/blender/python/bmesh/bmesh_py_types.c @@ -2040,12 +2040,15 @@ static void bpy_bmesh_dealloc(BPy_BMesh *self) { BMesh *bm = self->bm; - BM_data_layer_free(bm, &bm->vdata, CD_BM_ELEM_PYPTR); - BM_data_layer_free(bm, &bm->edata, CD_BM_ELEM_PYPTR); - BM_data_layer_free(bm, &bm->pdata, CD_BM_ELEM_PYPTR); - BM_data_layer_free(bm, &bm->ldata, CD_BM_ELEM_PYPTR); + /* have have been freed by bmesh */ + if (bm) { + BM_data_layer_free(bm, &bm->vdata, CD_BM_ELEM_PYPTR); + BM_data_layer_free(bm, &bm->edata, CD_BM_ELEM_PYPTR); + BM_data_layer_free(bm, &bm->pdata, CD_BM_ELEM_PYPTR); + BM_data_layer_free(bm, &bm->ldata, CD_BM_ELEM_PYPTR); - bm->py_handle = NULL; + bm->py_handle = NULL; + } PyObject_DEL(self); } @@ -2384,6 +2387,7 @@ PyObject *BPy_BMesh_CreatePyObject(BMesh *bm) else { self = PyObject_New(BPy_BMesh, &BPy_BMesh_Type); self->bm = bm; + bm->py_handle = self; /* point back */ BM_data_layer_add(bm, &bm->vdata, CD_BM_ELEM_PYPTR); BM_data_layer_add(bm, &bm->edata, CD_BM_ELEM_PYPTR); |