Hi All,
I am writing an MFC Tic Tac Toe app and I am getting a strange error when debugging it. This module loads a bunch of BOOL variables to keep track of whether or not the tile next to it matches (i.e is the tile next to me also an 'X' tile or is it an 'O' tile). The problem I'm having is that the if() statement checks to make sure that the tile that I am currently checking is not out of bounds (off the board). Here is an example:
if (k - 1 < 0 || j - 1 < 0);
else
{
if (tileMap[k][j]->GetTileType() == tileMap[k - 1][j - 1]->GetTileType() &&
tileMap[k][j]->GetTileType() != -1)
tileMap[k][j]->ulCorner = TRUE;
}
Just to let you know tileMap is of type
CTile *tileMap[3][3]
(CTile is inherited from CBitmapButton, it is a 2D array of pointers to store the tiles) Also, the if statement just ends in a semicolon because if that is true I just want the else block skipped completely and to move onto the next segment. So if k - 1 or j - 1 < 0 this means that it is off the board and the else statement should not execute because it would be an array out of bounds exception. So if the if() statement is true the else block should not excecute at all because k-1 or j-1 would be out of the array. When running the debugger and I get to this segment, as soon as it gets past the if() statement I get the error "Access violation reading location 0xcccccd40." because it is still trying to call GetTileType() on an array index that is outside the array bounds. If I comment out the second if statement the code continues past this point without error. How can I make it so that this error doesn't keep haunting my life?? :confused: