Fix T38493: ray_cast causes runtime error with no faces

This commit is contained in:
Campbell Barton 2014-05-22 17:10:21 +10:00
parent 1cf5e95f3d
commit c6de033bf1
Notes: blender-bot 2023-02-14 20:10:53 +01:00
Referenced by issue blender/blender-addons#38493, Templates: Raycast Modal Op does not catch RuntimeError caused by Object.ray_cast for meshes with no faces
1 changed files with 2 additions and 6 deletions

View File

@ -276,7 +276,6 @@ static int dm_tessface_to_poly_index(DerivedMesh *dm, int tessface_index)
return ORIGINDEX_NONE;
}
/* BMESH_TODO, return polygon index, not tessface */
static void rna_Object_ray_cast(Object *ob, ReportList *reports, float ray_start[3], float ray_end[3],
float r_location[3], float r_normal[3], int *index)
{
@ -290,11 +289,8 @@ static void rna_Object_ray_cast(Object *ob, ReportList *reports, float ray_start
/* no need to managing allocation or freeing of the BVH data. this is generated and freed as needed */
bvhtree_from_mesh_faces(&treeData, ob->derivedFinal, 0.0f, 4, 6);
if (treeData.tree == NULL) {
BKE_reportf(reports, RPT_ERROR, "Object '%s' could not create internal data for ray casting", ob->id.name + 2);
return;
}
else {
/* may fail if the mesh has no faces, in that case the ray-cast misses */
if (treeData.tree != NULL) {
BVHTreeRayHit hit;
float ray_nor[3], dist;
sub_v3_v3v3(ray_nor, ray_end, ray_start);