Can you share your code for CCell::setCellValue()? Also, what are the values of width and height when you are debugging?
Edit: Ah, nevermind, now I see the problem... Try this instead:
void CGrid::clearMap()
{
int i = 0;
int j = 0;
for(i = 0; i < width; i++)
{
for(j = 0; j < height; j++)
{
grid[i * height + j].setCellVal(0);
}
}
}
void CGrid::clearMap()
{
int i = 0;
int j = 0;
for(i = 0; i < width; i++)
{
for(j = 0; j < height; j++)
{
grid[i * height + j].setCellVal(0);
}
}
}
To copy to clipboard, switch view to plain text mode
You were blowing out the bounds of the QVector by computing an index outside of the range of your QVector that contains 600 items. As soon as you hit index 600, kaboom! Bugs like this are easier to spot if you use a variable for the index instead of a computation. For example:
int index = i * height + j;
grid[index].setCellVal(0);
int index = i * height + j;
grid[index].setCellVal(0);
To copy to clipboard, switch view to plain text mode
The above would have been much easier to spot IMHO...
Bookmarks