Hi,
i got a strange SegFault when trying to allocate memory (malloc).
First i setup the object like this:
all goes well until i try to allocate memory iside the buildTree method. i got an ugly Segmentation Fault.Code://global Accelerator_KDTree *g_KdTree; //KD-Tree Objectpointer ... int main(void) { ... g_KdTree = new Accelerator_KDTree(SIMPLE); //create the object int res = g_KdTree->init(&Geometry, 1); // call init method ... }
I get the SegFault when i try to call push_back on my STL list. After debugging a bit i knew that the SegFault happens when push_back calls malloc(). So i tried to call a malloc() directly and guess what... SEGFAULTCode:void Accelerator_KDTree::buildTree(POG* pog, int count) { printf("constructing KD-Tree...\n"); pc= new PrimitiveContainer(pog,count); KDTreeNode::pc=pc; KDTreeNode::maxDepth=512; KDTreeNode::cutoff=8; // WTF? //float* blah = (float*) malloc(10*sizeof(float)); // SEGFAULT!!! std::list<int> plist; AABoundingBox aabb; for(int i=0;i<pc->primitiveCount;i++) { //fill primitive list plist.push_back(i); // SEGFAULT (when template calls malloc) //construct axis aligned bounding box aabb.pmax.x=MAX2(aabb.pmax.x,pc->getMaxAxisValue(i,0)); aabb.pmax.y=MAX2(aabb.pmax.y,pc->getMaxAxisValue(i,1)); aabb.pmax.z=MAX2(aabb.pmax.z,pc->getMaxAxisValue(i,2)); aabb.pmin.x=MIN2(aabb.pmin.x,pc->getMinAxisValue(i,0)); aabb.pmin.y=MIN2(aabb.pmin.y,pc->getMinAxisValue(i,1)); aabb.pmin.z=MIN2(aabb.pmin.z,pc->getMinAxisValue(i,2)); } root= KDTreeNode::buildTree(plist,aabb,4); printf("complete. %i nodes, max depth: %i,min depth: %i, avg depth: %i, %i",KDTreeNode::nodecount,KDTreeNode::treedepth,KDTreeNode::treemindepth,KDTreeNode::avgdepth,KDTreeNode::primcount); }
I have no idea what goes wrong here so i would be grateful for any hint what possibly could cause this. Maybe i just miss something stupid.
Greets
cipher



LinkBack URL
About LinkBacks







