I keep getting a segfault with the following code, the only thing I have been able to gather is that I always get the segfault when "val" is 2.
*stopped,reason="signal-received",signal-name="SIGSEGV",signal-meaning="Segmentation fault",thread-id="1",frame={addr="0x004015f4",func="theoFlood",a rgs=[{name="x",value="1"},{name="y",value="4"},{name="v al",value="2"}],file="../src/solve.cpp",fullname="C:/Users/Admin/workspace/Flood It/Debug/../src/solve.cpp",line="86"}
Code:
int efficient[6];
extern const int gridsize = 14;
extern int grid[gridsize][gridsize];
[. . .]
for (int z = 0; z < 6; z++) // Theoretically runs through all possibilities
{
for (int x = 0; x < gridsize; x++)
for (int y = 0; y < gridsize; y++)
if (grid[x][y] == z)
theoFlood(x, y, z + 1);
}
[. . .]
void theoFlood(int x, int y, int val)
{
efficient[val - 1]++;
if (x)
if (grid[x-1][y] == val)
theoFlood(x-1, y, val);
if (y)
if (grid[x][y-1] == val)
theoFlood(x, y-1, val);
if (grid[x+1][y] == val)
theoFlood(x+1, y, val);
if (grid[x][y+1] == val)
theoFlood(x, y+1, val);
}