Templates: Raycast Modal Op does not catch RuntimeError caused by Object.ray_cast for meshes with no faces #38493

Closed
opened 2014-02-05 03:13:15 +01:00 by CodeManX · 10 comments
Member

ray_cast() raises a RuntimeError if a mesh has no faces:

RuntimeError: Error: Object 'Plane' could not create internal data for ray casting

The template does neither check for len(obj.data.polygons) < 1, nor try/catch the exception.

`ray_cast()` raises a RuntimeError if a mesh has no faces: ``` RuntimeError: Error: Object 'Plane' could not create internal data for ray casting ``` The template does neither check for `len(obj.data.polygons) < 1`, nor try/catch the exception.
Author
Member

Changed status to: 'Open'

Changed status to: 'Open'
Author
Member

Added subscriber: @CodeManX

Added subscriber: @CodeManX
Campbell Barton was assigned by Sergey Sharybin 2014-02-06 08:52:29 +01:00

Added subscribers: @ideasman42, @Sergey

Added subscribers: @ideasman42, @Sergey

Not sure whether templates should handle all sorts of issues. They're more like hints how to do the things.

@ideasman42, leaving this one for you.

Not sure whether templates should handle all sorts of issues. They're more like hints how to do the things. @ideasman42, leaving this one for you.
Author
Member

There's no indication in the API docs, that ray_cast could ever raise an exception, so why would it be inappropriate to add this check if everyone should do it this way?

There's no indication in the API docs, that ray_cast could ever raise an exception, so why would it be inappropriate to add this check if everyone should do it this way?

Added subscriber: @AtomP

Added subscriber: @AtomP

It also raises an exception in official 2.70 if the mesh is in edit mode.

Try this on the default cube in edit mode.

import bpy
ob = bpy.data.objects.get("Cube")
polys = ob.data.polygons

end = polys[0].normal.copy() * -1   #Invert the normal because we are bouncing around inside the mesh.
start = polys[0].center
dist = 1000
hit, nor, index = ob.ray_cast(start, end * dist)
It also raises an exception in official 2.70 if the mesh is in edit mode. Try this on the default cube in edit mode. ``` import bpy ``` ``` ob = bpy.data.objects.get("Cube") polys = ob.data.polygons end = polys[0].normal.copy() * -1 #Invert the normal because we are bouncing around inside the mesh. start = polys[0].center dist = 1000 hit, nor, index = ob.ray_cast(start, end * dist) ```

This issue was referenced by blender/blender@c6de033bf1

This issue was referenced by blender/blender@c6de033bf1e92dd94858e8998f154fdea2e6bee2

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'

Closed by commit blender/blender@c6de033bf1.

Closed by commit blender/blender@c6de033bf1.
Sign in to join this conversation.
No Milestone
No project
No Assignees
5 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#38493
No description provided.