bvh icon indicating copy to clipboard operation
bvh copied to clipboard

panicked at assertion failed: !child_l_aabb.is_empty()

Open tlaukkan opened this issue 4 years ago • 6 comments

Hi

I am building BVH consisting of triangles for ray casting. I am using the triangle code from testbase.rs. The crate versions are:

nalgebra = "0.20"
bvh = "0.3.2"

The code works with a simple box test case but when I try to load larger mesh with something like this I get the following error:

triangle #0 (0,0,0) (0,0,0) (0,0,0) 
triangle #1 (0,0,0) (0,0,0) (0,0,1) 
panicked at 'assertion failed: !child_l_aabb.is_empty()', <::std::macros::panic macros>:2:4

The problem seems to appear when there is triangle with all vertexes in same coordinates and another with one vertex translated only in one dimension.

It could be good idea to fail fast when dot (0 dimensional) or line (1 dimensional) shapes are added.

Kind regards, Tommi

tlaukkan avatar May 10 '20 04:05 tlaukkan

I've had this same problem happen. For example, loading the famous san miguel scene from https://casual-effects.com/data/ causes this crash.

Is there a simple way to circumvent this issue without modifying the library code?

[[package]]
name = "bvh"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b0ad6e8f606aa0912fbc0a5992893800ed795f46dd419f6b1727f10da7cc9c5"
dependencies = [
 "approx",
 "glam",
 "log",
 "num",
 "rand",
]

tonihW avatar Apr 18 '23 11:04 tonihW

You can modify library and I will merge it. In fact I'd be quite glad if you did.

svenstaro avatar Apr 18 '23 11:04 svenstaro

You can modify library and I will merge it. In fact I'd be quite glad if you did.

Well I can try, but I need to learn more about BVH's first. For my case the simple incorrect fix was to remove the assertions in the library for the child node is_empty checks. So now I have a BVH with some empty child AABB's but it renders just fine enough for me. I have no idea yet why they are empty though, I've added assertions for my triangle AABB construction method to make sure that my triangle AABB's are correct and they are, none are empty.

edit: Somehow, the result of grow_convex_hull's aabb_bounds surface area equals to 0.0 , which causes division by zero and then causes the branches to remain empty.

tonihW avatar Apr 19 '23 09:04 tonihW

You can modify library and I will merge it. In fact I'd be quite glad if you did.

The mesh that I encountered this problem with contains triangles which have AABB's like the following: AABB { min: Vec3(6.57905, 6.87636, 11.8601), max: Vec3(6.57906, 6.87636, 11.8601) }

So I guess it's a problem with the data, not the library. But should the BVH library handle such a case without crashing? I've encountered this same problem with multiple meshes, I'm just loading the raw OBJ mesh data and not filtering it at all.

tonihW avatar Apr 19 '23 12:04 tonihW

I think this can be closed since I cannot find an issue with the library itself, the issue is in providing valid geometric shapes to the library, at least in my case.

tonihW avatar Apr 21 '23 12:04 tonihW

We could add a better message here perhaps into the assert to give people an idea what might be wrong? Not sure. Would you like to try? @marstaik WDYT?

svenstaro avatar Apr 22 '23 02:04 svenstaro