I'm working on a Minesweeper clone to get practice on Win32. I have a global array of structs called tile_array. This is an array of structs called "tile." Each tile struct contains the x coordinate, y coordinate, whether there's a mine in the tile, whether there's a mine next to it, etc.
First, I've declared this in my header file so various different .cpp files in the Solution can use it. It's defined as an extern.
extern tile *tile_array;
Then, it's declared again at the to of my main .cpp file.
tile *tile_array = NULL;
After the user has inputted how many tiles they want horizontal and vertical, and how many mines will be on the field, the total tiles needed are calculated and the memory is allocated based on the total tiles. (For purposes of testing, the horizontal, vertical, and mine count are temporarily hardcoded.)
1 2 3 4 5 6 7 8
|
tiles_horiz = 10; //temp code
tiles_vert = 10; //temp code
num_mines = 5; //temp code
...
tiles_total = (tiles_horiz * tiles_vert);
tile_array = new tile[tiles_total];
|
Whenever I delete tile_array using the delete[] operator, I get a heap corruption error from Visual Studio. It doesn't say that's the error specifically, but it forces a break in the debugger and the problem is always in free.c
Right now I have the delete operator placed toward the end of the program when it's ready to exit. But my intention is to use it if the player resets, too, so that the tile_array array and be slept clean and reset based on any new selections.