Fix #116262: Modal knife tool can crash if used on hidden object

This could happen if objects were hidden after going to editmode and
knife was used on them.

In that case, raycasting would (rightfully) fail, but there is a
fallback in place using the back-buffer selection method (in which the
hidden object is still present). So a face would be found, but this
makes all following code confusing/wrong since we are working with
coordinates / faces under the assumption there would be a valid/
corresponding object to it in `KnifeTool_OpData` > `objects` -- which is
not the case...

So to resolve, just check if the object is visible before calling
`EDBM_face_find_nearest` in knife code.

Alternativeliy, we could also add a check for Base viewport visibility
to all the bmesh `find_nearest` functions (a bit hesitant though since i
am not sure this would be desired in all cases)

Pull Request: https://projects.blender.org/blender/blender/pulls/119383
This commit is contained in:
Philipp Oeser
2024-03-12 17:02:35 +01:00
committed by Philipp Oeser
parent 9ee45646b4
commit 2886859347
@@ -3213,7 +3213,9 @@ static BMFace *knife_find_closest_face(KnifeTool_OpData *kcd,
vc.mval[0] = int(kcd->curr.mval[0]);
vc.mval[1] = int(kcd->curr.mval[1]);
f = EDBM_face_find_nearest(&vc, &dist);
if (BKE_object_is_visible_in_viewport(vc.v3d, vc.obact)) {
f = EDBM_face_find_nearest(&vc, &dist);
}
/* Cheat for now; just put in the origin instead
* of a true coordinate on the face.