wahn / rs_pbrt

Rust crate to implement a counterpart to the PBRT book's (3rd edition) C++ code. See also https://www.rs-pbrt.org/about ...
https://www.rs-pbrt.org
Other
811 stars 59 forks source link

[panic] in BVHAccel::recursive_build() #96

Closed wahn closed 5 years ago

wahn commented 5 years ago
> pwd
/mill3d/users/jan/Graphics/Rendering/PBRT/pbrt-v3-scenes/coffee-splash
> ~/git/github/rs_pbrt/target/release/examples/rs_pbrt -i f15-5.pbrt
pbrt version 0.5.3 [Detected 8 cores]
Copyright (c) 2016-2019 Jan Douglas Bert Walter.
Rust code based on C++ code by Matt Pharr, Greg Humphreys, and Wenzel Jakob.
Sampler "sobol"
  "integer pixelsamples" [8]
Integrator "volpath"
  "integer maxdepth" [25]
Film "image"
  "string filename" ["f15-5.exr"]
  "integer xresolution" [1000]
  "integer yresolution" [800]
  "float scale" [2]
Include "/mill3d/users/jan/Graphics/Rendering/PBRT/pbrt-v3-scenes/coffee-splash/materials.pbrt"
reading "bsdfs/ceramic.bsdf" returns true
Include "/mill3d/users/jan/Graphics/Rendering/PBRT/pbrt-v3-scenes/coffee-splash/geometry.pbrt"
reading "bsdfs/ceramic.bsdf" returns true
BVHAccel::recursive_build(..., 0, ...)
thread 'main' panicked at 'assertion failed: `(left != right)`
  left: `0`,
 right: `0`', src/accelerators/bvh.rs:210:9
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
wahn commented 5 years ago

On the C++ side we can set a breakpoint here (in src/shapes/plymesh.cpp):

B+ │285         return CreateTriangleMesh(o2w, w2o, reverseOrientation,
   │286                                   context.indexCtr / 3, context.indices,
   │287                                   vertexCount, context.p, nullptr, context.n,
   │288                                   context.uv, alphaTex, shadowAlphaTex,
  >│289                                   context.faceIndices);

At that point we have read 3970 vertices and 23808 indices (divided by 3, means 7936 triangles):

(gdb) p context.indexCtr
$3 = 23808
(gdb) p vertexCount 
$7 = 3970

Debugging the Rust side (in shapes/plymesh.rs):

    let mesh = Arc::new(TriangleMesh::new(                                                              
        *o2w,                                                                                           
        *w2o,                                                                                           
        reverse_orientation,                                                                            
        tm_vertex_indices.len() / 3, // n_triangles                                                     
        tm_vertex_indices,                                                                              
        n_vertices,                                                                                     
        p_ws, // in world space                                                                         
        s_ws, // in world space                                                                         
        n_ws, // in world space                                                                         
        uvs,                                                                                            
    ));                                                                                                 

We find the same amount of read vertices:

(gdb) p n_vertices
$15 = 3970

But the vertex indices are missing!!!

(gdb) p tm_vertex_indices
$16 = Vec<usize>(len: 0, cap: 0)
wahn commented 5 years ago

Commit 056f2e43ef71a985d4a8666fee9cae3e76bfd3b5 fixes the issue and also fixes a bug in create_ply_mesh(...) regarding quads.