My problem is with my Map class. My map class parses a text file (which is a text version of the map grid), and reads all 1s as Walls and all 0s as blank spaces. The 0s are ignored, and for each 1 that it encounters, it takes the coordinates of the '1' and creates a pointer to a Wall object with those coordinates, and adds it to my _mazeMap vector.
vector _mazeMap;
_mazeMap.push_back(new Wall(x, y));
is the gist of it.
My problem is cleaning up the memory. In my Map class' destructor I figure I need to delete all the pointers that were created in the vector, correct? So this is the code I wrote to try and do it:
Map::~Map()
{
std::vector::iterator iter = _mazeMap.begin();
for (iter = _mazeMap.begin(); iter != _mazeMap.end(); ++iter)
{
delete *iter;
}
}
However, every time I run the game, when I shut it down, and the Destructor gets run, I get this error:
Thread 1: Program received signal: "EXC_BAD_ACCESS"
I have no idea what I'm doing wrong. Any help? Thanks so much.