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
This commit is contained in:
Sonny Campbell 2022-09-06 13:09:01 -05:00 committed by Philipp Oeser
parent 5e372fca7c
commit 8004214356
Notes: blender-bot 2023-02-14 10:43:47 +01:00
Referenced by issue #100749, Blender LTS: Maintenance Task 3.3
Referenced by issue #99141, Regression: "Copy Location" constraint doesn't work if the control object is a vertex and we're in edit mode.
1 changed files with 18 additions and 18 deletions

View File

@ -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;