This:
bool grid[1280][1024];
for (int x = 0; x<1280; x++)
{
for (int y = 0; y<1024; y++)
{
grid[x][y] = false;
}
}
works fine, but
bool grid[1280][1024];
bool grid2[1280][1024];
for (int x = 0; x<1280; x++)
{
for (int y = 0; y<1024; y++)
{
grid[x][y] = false;
grid2[x][y] = false;
}
}
gives me a segfault. Why?
Probably not enough stack space, your second example also crashes on my PC. Try allocating on the heap, or even better, use a proper container class:
Note how I switched the width and the height. You probably want your elements aligned this way to ensure fast linear access.