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
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-04-30 00:21:19 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-04-30 00:21:19 +0400
commit1edf56e7a5998b5f2efdb4f96883556923376eb6 (patch)
tree27bf80d9d1009184c2eb86cbd385c98155753eb9 /source
parentaa2a0e4ab00a803743141af258a1ff1515182420 (diff)
fix [#35150] Crash when bmesh operation called from within a Panel draw()
accessing a bmesh from python would reallocate all customdata layers. add an assert to BM_data_layer_free(), when its called unnecessarily since its reallocating all layers.
Diffstat (limited to 'source')
-rw-r--r--source/blender/bmesh/intern/bmesh_interp.c10
-rw-r--r--source/blender/python/bmesh/bmesh_py_types.c11
2 files changed, 15 insertions, 6 deletions
diff --git a/source/blender/bmesh/intern/bmesh_interp.c b/source/blender/bmesh/intern/bmesh_interp.c
index c0975897090..290c6d9c9c8 100644
--- a/source/blender/bmesh/intern/bmesh_interp.c
+++ b/source/blender/bmesh/intern/bmesh_interp.c
@@ -804,6 +804,7 @@ void BM_data_layer_add_named(BMesh *bm, CustomData *data, int type, const char *
void BM_data_layer_free(BMesh *bm, CustomData *data, int type)
{
CustomData olddata;
+ bool has_layer;
olddata = *data;
olddata.layers = (olddata.layers) ? MEM_dupallocN(olddata.layers): NULL;
@@ -811,7 +812,9 @@ void BM_data_layer_free(BMesh *bm, CustomData *data, int type)
/* the pool is now owned by olddata and must not be shared */
data->pool = NULL;
- CustomData_free_layer_active(data, type, 0);
+ has_layer = CustomData_free_layer_active(data, type, 0);
+ /* assert because its expensive to realloc - better not do if layer isnt present */
+ BLI_assert(has_layer != false);
update_data_blocks(bm, &olddata, data);
if (olddata.layers) MEM_freeN(olddata.layers);
@@ -820,6 +823,7 @@ void BM_data_layer_free(BMesh *bm, CustomData *data, int type)
void BM_data_layer_free_n(BMesh *bm, CustomData *data, int type, int n)
{
CustomData olddata;
+ bool has_layer;
olddata = *data;
olddata.layers = (olddata.layers) ? MEM_dupallocN(olddata.layers): NULL;
@@ -827,7 +831,9 @@ void BM_data_layer_free_n(BMesh *bm, CustomData *data, int type, int n)
/* the pool is now owned by olddata and must not be shared */
data->pool = NULL;
- CustomData_free_layer(data, type, 0, CustomData_get_layer_index_n(data, type, n));
+ has_layer = CustomData_free_layer(data, type, 0, CustomData_get_layer_index_n(data, type, n));
+ /* assert because its expensive to realloc - better not do if layer isnt present */
+ BLI_assert(has_layer != false);
update_data_blocks(bm, &olddata, data);
if (olddata.layers) MEM_freeN(olddata.layers);
diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c
index fc69f81820a..3da47d22d90 100644
--- a/source/blender/python/bmesh/bmesh_py_types.c
+++ b/source/blender/python/bmesh/bmesh_py_types.c
@@ -2943,10 +2943,10 @@ static void bpy_bmesh_dealloc(BPy_BMesh *self)
if (bm) {
bm_dealloc_editmode_warn(self);
- 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);
+ if (CustomData_has_layer(&bm->vdata, CD_BM_ELEM_PYPTR)) BM_data_layer_free(bm, &bm->vdata, CD_BM_ELEM_PYPTR);
+ if (CustomData_has_layer(&bm->edata, CD_BM_ELEM_PYPTR)) BM_data_layer_free(bm, &bm->edata, CD_BM_ELEM_PYPTR);
+ if (CustomData_has_layer(&bm->pdata, CD_BM_ELEM_PYPTR)) BM_data_layer_free(bm, &bm->pdata, CD_BM_ELEM_PYPTR);
+ if (CustomData_has_layer(&bm->ldata, CD_BM_ELEM_PYPTR)) BM_data_layer_free(bm, &bm->ldata, CD_BM_ELEM_PYPTR);
bm->py_handle = NULL;
@@ -3370,10 +3370,13 @@ PyObject *BPy_BMesh_CreatePyObject(BMesh *bm, int flag)
bm->py_handle = self; /* point back */
+ /* avoid allocating layers when we don't have to */
+#if 0
BM_data_layer_add(bm, &bm->vdata, CD_BM_ELEM_PYPTR);
BM_data_layer_add(bm, &bm->edata, CD_BM_ELEM_PYPTR);
BM_data_layer_add(bm, &bm->pdata, CD_BM_ELEM_PYPTR);
BM_data_layer_add(bm, &bm->ldata, CD_BM_ELEM_PYPTR);
+#endif
}
return (PyObject *)self;