Hello,
I am writing a raytracer, and currently I'm working on creating a bounding volume hierarchy to accelerate the process. To do this, I am first creating a vector that holds each of the objects in the scene, and passing this vector to the constructor for my BVH.
Code:
//in header
BVH_Node* bvh;
//in main raytrace function
bvh = new BVH_Node(objList,0);
The BVH_Node constructor:
Code:
//here's how the beginning of it looks
BVH_Node::BVH_Node(vector<GeomObj*> list, int axis){
int size = list.size(); //number of elements in list
this->isObj = false;
if(size == 1){
this->left = makeLeaf(list[0]);
this->right = makeLeaf(NULL);
this->bb = list[0]->bb;
return;
}
if(size == 2){
this->left = makeLeaf(list[0]);
this->right = makeLeaf(list[1]);
this->bb = combineBoxes(list[0]->bb,list[1]->bb);
return;
}
//the rest of it
}
I am testing a scene that has only 2 objects, and so it goes to the size == 2 check. The first time it hits makeLeaf(), I segfault. I've used both gdb and valgrind, and of course it's a memory mapping error. gdb's backtrace tells me that the length of the vector I've passed in is -805305610 and the capacity is -21, and that it is inside my makeLeaf() function that the error occurs. Here's the function:
Code:
BVH_Node* BVH_Node::makeLeaf(GeomObj* v){
BVH_Node* node;
node->obj = v;
node->isObj = true;
return node;
}
The segfault happens at Could someone help me understand why this is happening? If I run my raytracer without a BVH, the objList works perfectly.
Thanks