Try to find a minimal case that triggers the bug, i.e. a small model with only a few triangles. Then step through the code in the debugger and see what’s going on. With a small number of triangles the amount of data should be small enough that you can figure out the problem. If the problem disappears with smaller models that’s information too.

I have implemented the kd-tree found in pbrt v2, and it works, kind of. At the part where you build the tree, you sort the list of point from the triangle list for the current axis to get the split pos to test against. I’m getting a few triangles here and there that are missing from the render (invisible). if I change the sorting algo from quick sort to another, then I get different sets of missing triangles. I check over and over and over, and the code is identical to that of pbrt, even the kd ray intersect. The model I used is not corrupted in any ways, openGL displays it nicely, and it does this on all models. It always seems to come from the way the list is sorted. Anyone may have a clue as to what this problem maybe? Thanks!