I have a piece of code that is creating a tile based level.
class Level {
//Variables
//===================================================
public:
Tile *** TileGrid; //A 2d array of pointers to tiles
int TilesWide, TilesTall;
//Methods
//===================================================
public:
Level::Level(char * fileName);
Level::~Level();
void Draw();
};
I allocate memory for the TileGrid and all is good. I have a destructor set up for the class too.
Level::~Level() {
for (int i = 0; i < TilesTall; i++) {
for (int j = 0; j < TilesWide; j++)
//delete the looped tile being pointed to
delete TileGrid[i][j];
//delete the row
delete [] TileGrid[i];
}
//delete the array of rows
delete [] TileGrid;
}
For giggles I decided I would delete my instance of Level. After I did so, I found that I could still call its Draw method.
In the debugger the values for TilesWide and TilesTall are a huge negative numbers, so nothing draws in my for loops iterating the grid.
Would trying to access a deleted variable not cause some sort of crash?