X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=bvh.h;fp=bvh.h;h=84f4c6b7d675c7b1cfdf9f914722b572424aa347;hb=1f0e3292c021e8263716e5f4544a1efcedf3f03d;hp=9fdbe985040f51e0cadfd0a183b921240c82a036;hpb=be6707a307bfeec1b45cca8b3fb647e81262be87;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/bvh.h b/bvh.h index 9fdbe98..84f4c6b 100644 --- a/bvh.h +++ b/bvh.h @@ -137,6 +137,15 @@ VG_STATIC void bh_subdivide( bh_tree *bh, u32 inode ) VG_STATIC bh_tree *bh_create( void *lin_alloc, bh_system *system, void *user, u32 item_count ) { + if( item_count == 0 ) + { + bh_tree *bh = vg_linear_alloc( lin_alloc, sizeof(bh_tree) ); + bh->node_count = 0; + bh->system = system; + bh->user = user; + return bh; + } + u32 totsize = sizeof(bh_tree) + sizeof(bh_node)*(item_count*2-1); bh_tree *bh = vg_linear_alloc( lin_alloc, totsize ); bh->system = system; @@ -192,6 +201,9 @@ VG_STATIC void bh_debug_node( bh_tree *bh, u32 inode, v3f pos, u32 colour ) VG_STATIC int bh_ray( bh_tree *bh, v3f co, v3f dir, ray_hit *hit ) { + if( bh->node_count < 2 ) + return 0; + int count = 0; u32 stack[100]; u32 depth = 2; @@ -243,6 +255,9 @@ VG_STATIC int bh_ray( bh_tree *bh, v3f co, v3f dir, ray_hit *hit ) VG_STATIC int bh_select( bh_tree *bh, boxf box, u32 *buffer, int len ) { + if( bh->node_count < 2 ) + return 0; + int count = 0; u32 stack[100]; u32 depth = 2;