Original Post
I'm showing only a couple memory leaks when the program exits. When I set a breakpoint on the allocation number, it's deep down in STL and traces back to the vector class. I know it's a problem with how I'm using it, but I'm not sure what's wrong. Basically I have a vector of a list. This is ok, right? Like this: And I am deleting it like so. I have to do it this way because FreeUploadedVertexData and FreeVertexBuffer pushes the buffer to the front of the list and makes any iterator invalid. I have a feeling my error is in here. I have debugged though and this does go through every node, since every time the node is pushed to the front, back() successfully gets the next one. Can anyone see a problem with this?
typedef std::list< AXVertexBuffer* > VertexBufferList;
typedef std::vector< VertexBufferList > Buffer2DArray;
I am creating the buffers by looping through and creating the list, and then attaching the list to the vector like so:
for(unsigned int i=0; i<=6; i++) {
VertexBufferList BufferVector;
for(unsigned int j=0; j<NumBuffers; j++) {
AXVertexBuffer *Buffer = new AXVertexBuffer;
/* init stuff*/
BufferVector.push_back(Buffer);
}
_VertexBuffers.push_back(BufferVector);
}
/* Delete vertex buffers */
for(unsigned int i=0; i<(unsigned int)_VertexBuffers.size(); i++) {
/* We do it this way because FreeUploadedVertexData changes the
order of the list and would make our iterator invalid */
for(unsigned int j=0; j<(unsigned int)_VertexBuffers.size(); j++) {
AXVertexBuffer *Buffer = _VertexBuffers.back();
UnlockVertexBuffer(Buffer);
if(Buffer->Owner) Buffer->Owner->FreeUploadedVertexData();
else FreeVertexBuffer(Buffer);
SafeDelete(Buffer);
}
_VertexBuffers.clear();
}
_VertexBuffers.clear();