diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2018-12-27 19:18:05 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2018-12-27 19:21:17 +0300 |
commit | b3e68a83f30f7f9948a384d756aaf43eb055ab46 (patch) | |
tree | a13480aa9e832a7d59b9fb158650504027c28bd5 /source | |
parent | b2a7aab7db81557ef3f2f8bd1df7ce8e37e137a6 (diff) |
Fix T58734: bvhtree.fromObject - error ( returned NULL without setting an error) in blender 2.8.
Would free evaluated mesh even when it was the one cached in runtime
data by depsgraph evaluation!
Also fixes the asserts about using non-eval object in some cases.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/python/mathutils/mathutils_bvhtree.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/source/blender/python/mathutils/mathutils_bvhtree.c b/source/blender/python/mathutils/mathutils_bvhtree.c index b247123ecff..fce0dd7d2af 100644 --- a/source/blender/python/mathutils/mathutils_bvhtree.c +++ b/source/blender/python/mathutils/mathutils_bvhtree.c @@ -1053,11 +1053,13 @@ static PyObject *C_BVHTree_FromBMesh(PyObject *UNUSED(cls), PyObject *args, PyOb /* return various derived meshes based on requested settings */ static Mesh *bvh_get_mesh( const char *funcname, struct Depsgraph *depsgraph, struct Scene *scene, Object *ob, - bool use_deform, bool use_cage) + const bool use_deform, const bool use_cage, bool *r_free_mesh) { + Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); /* we only need minimum mesh data for topology and vertex locations */ CustomDataMask mask = CD_MASK_BAREMESH; const bool use_render = DEG_get_mode(depsgraph) == DAG_EVAL_RENDER; + *r_free_mesh = false; /* Write the display mesh into the dummy mesh */ if (use_deform) { @@ -1068,17 +1070,23 @@ static Mesh *bvh_get_mesh( return NULL; } else { + *r_free_mesh = true; return mesh_create_eval_final_render(depsgraph, scene, ob, mask); } } - else { + else if (ob_eval != NULL) { if (use_cage) { - return mesh_get_eval_deform(depsgraph, scene, ob, mask); /* ob->derivedDeform */ + return mesh_get_eval_deform(depsgraph, scene, ob_eval, mask); /* ob->derivedDeform */ } else { - return mesh_get_eval_final(depsgraph, scene, ob, mask); /* ob->derivedFinal */ + return mesh_get_eval_final(depsgraph, scene, ob_eval, mask); /* ob->derivedFinal */ } } + else { + PyErr_Format(PyExc_ValueError, + "%s(...): Cannot get evaluated data from given dependency graph / object pair", funcname); + return NULL; + } } else { /* !use_deform */ @@ -1089,6 +1097,7 @@ static Mesh *bvh_get_mesh( return NULL; } else { + *r_free_mesh = true; return mesh_create_eval_no_deform_render(depsgraph, scene, ob, NULL, mask); } } @@ -1099,6 +1108,7 @@ static Mesh *bvh_get_mesh( return NULL; } else { + *r_free_mesh = true; return mesh_create_eval_no_deform(depsgraph, scene, ob, NULL, mask); } } @@ -1132,6 +1142,7 @@ static PyObject *C_BVHTree_FromObject(PyObject *UNUSED(cls), PyObject *args, PyO Mesh *mesh; bool use_deform = true; bool use_cage = false; + bool free_mesh = false; const MLoopTri *lt; const MLoop *mloop; @@ -1154,7 +1165,7 @@ static PyObject *C_BVHTree_FromObject(PyObject *UNUSED(cls), PyObject *args, PyO } scene = DEG_get_evaluated_scene(depsgraph); - mesh = bvh_get_mesh("BVHTree", depsgraph, scene, ob, use_deform, use_cage); + mesh = bvh_get_mesh("BVHTree", depsgraph, scene, ob, use_deform, use_cage, &free_mesh); if (mesh == NULL) { return NULL; @@ -1212,7 +1223,9 @@ static PyObject *C_BVHTree_FromObject(PyObject *UNUSED(cls), PyObject *args, PyO BLI_bvhtree_balance(tree); } - BKE_id_free(NULL, mesh); + if (free_mesh) { + BKE_id_free(NULL, mesh); + } return bvhtree_CreatePyObject( tree, epsilon, |