Neighbors of cell are calculated out of the grid
From the commit 00c39787 the variable sum_neighbors
is calculated as follows:
int sum_neighbors = 0;
for(int x = -1; x<2; x++){
for(int y = -1; y<2; y++){
sum_neighbors += old_gen[i+x][j+y];
}
}
sum_neighbors-= old_gen[i][j];
this causes a problem since sum_neighbors
is calculated without consideration that the indexes x
and y
for the neighbors could be out of the range of the array old_gen
.
Example:
when x = -1
and i = 0
then old_gen[0-1][j+y]