So im trying to implement an octree for a 3d world. But im having some issues with "new" and pointers.
first problem is:
i can make a tree and i can print the contents of each node to the screen, but then if i try to go through the tree looking for what node a certain point is it crashes.
im using gcc v4. something on windows vista
attached is the code for the tree.
Any and all help is greatly appreciated.
Adam, if you provide me with a main program that creates the octree and reproduces the problem, I'll try to debug it. I need to be able to compile it, so I need VECTOR, TRIANGLE, and CVec3 (as far as I know).
Ok here are the files. (AFAIK, they dont have anything special to link to...) TextureManager isnt needed.
Thanks for your help.
Adam, the files in the last post don't compile.
and there is no map.txt.
1>octree\main.cpp(15) : error C2039: 'getTriangleList' : is not a member of 'C3DWorld'
1> octree\c3dworld.h(36) : see declaration of 'C3DWorld'
1>octree\c3dworld.cpp(26) : error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
I'll have a read through the OC tree code if I get some time.
i didnt include map.txt cause i can only upload 5 files at a time. Not sure why its giving you that error, it doesnt on my computer.
One source of memory corruption is that you've copied OCTree.h into OCTree.cpp and then changed struct OCTreeNode. In OCTree.h, OCTreeNode has int* polys. In OCTree.cpp, it has int polys. The mismatch in structure sizes has caused problems long before map.txt is even opened.
In loadWorld, you define
which is on the stack.
It should be on the heap
SECTOR* tsect = new SECTOR[numsect];
I removed the OCTree.h contents from OCTree.cpp and defined OCTreeNode in OCTree.h with int polys and I made the tsect on the heap.
That allowed the program to run with no visible errors.
I suppose you want to allocate polys on the heap, and the polys was just for testing.
Attached is the output. I did not try to interpret the output. It's up to you to check it.