diff options
author | Sonny Campbell <SonnyCampbell_Unity> | 2022-09-06 21:09:01 +0300 |
---|---|---|
committer | Philipp Oeser <info@graphics-engineer.com> | 2022-09-21 12:58:06 +0300 |
commit | 8004214356a4882606d92758f33954e5973fc591 (patch) | |
tree | 0b76dd1255c9fad6253a8b9f98045436124798b8 | |
parent | 5e372fca7c8153b631a63ade90896ceca2aa1b39 (diff) |
Fix T99141: Crash with edit mode and copy location constraint
The constraint attempted to access mesh normals on a mesh with
wrapper type ME_WRAPPER_TYPE_BMESH. This commit reverses the if
statements so that If there is an editmesh then we use that as the
source of truth - otherwise use the evaluated mesh.
Differential Revision: https://developer.blender.org/D15809
-rw-r--r-- | source/blender/blenkernel/intern/constraint.c | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 9f1d2d7bbb2..e2874f1a1c6 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -528,7 +528,24 @@ static void contarget_get_mesh_mat(Object *ob, const char *substring, float mat[ float vec[3] = {0.0f, 0.0f, 0.0f}; float normal[3] = {0.0f, 0.0f, 0.0f}; float weightsum = 0.0f; - if (me_eval) { + if (em) { + if (CustomData_has_layer(&em->bm->vdata, CD_MDEFORMVERT)) { + BMVert *v; + BMIter iter; + + BM_ITER_MESH (v, &iter, em->bm, BM_VERTS_OF_MESH) { + MDeformVert *dv = CustomData_bmesh_get(&em->bm->vdata, v->head.data, CD_MDEFORMVERT); + MDeformWeight *dw = BKE_defvert_find_index(dv, defgroup); + + if (dw && dw->weight > 0.0f) { + madd_v3_v3fl(vec, v->co, dw->weight); + madd_v3_v3fl(normal, v->no, dw->weight); + weightsum += dw->weight; + } + } + } + } + else if (me_eval) { const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(me_eval); const MDeformVert *dvert = CustomData_get_layer(&me_eval->vdata, CD_MDEFORMVERT); int numVerts = me_eval->totvert; @@ -550,23 +567,6 @@ static void contarget_get_mesh_mat(Object *ob, const char *substring, float mat[ } } } - else if (em) { - if (CustomData_has_layer(&em->bm->vdata, CD_MDEFORMVERT)) { - BMVert *v; - BMIter iter; - - BM_ITER_MESH (v, &iter, em->bm, BM_VERTS_OF_MESH) { - MDeformVert *dv = CustomData_bmesh_get(&em->bm->vdata, v->head.data, CD_MDEFORMVERT); - MDeformWeight *dw = BKE_defvert_find_index(dv, defgroup); - - if (dw && dw->weight > 0.0f) { - madd_v3_v3fl(vec, v->co, dw->weight); - madd_v3_v3fl(normal, v->no, dw->weight); - weightsum += dw->weight; - } - } - } - } else { /* No valid edit or evaluated mesh, just abort. */ return; |