Hello all, I'm trying to make a project which includes a square matrix of objects and for each entry I want to add a list of neighbours which are the 8 surrounding cells (cells on the edge of the matrix will connect to the other side, so each cell should have 8 neighbours). I have this piece of code:

int i;

int j;

for (i = 0; i<NCOL; i++) {

for (j = 0; j<NCOL; j++) {

mat[i][j].neigh.push_back(mat[(i-1+NCOL)%NCOL][(j-1+NCOL)%NCOL]);

//mat[i][j].neigh.push_back(mat[i][(j-1+NCOL)%NCOL]);

mat[i][j].neigh.push_back(mat[(i+1)%NCOL][(j-1+NCOL)%NCOL]);

mat[i][j].neigh.push_back(mat[(i-1+NCOL)%NCOL][j]);

mat[i][j].neigh.push_back(mat[(i+1)%NCOL][j]);

mat[i][j].neigh.push_back(mat[(i-1+NCOL)%NCOL][(j+1)%NCOL]);

mat[i][j].neigh.push_back(mat[i][(j+1)%NCOL]);

mat[i][j].neigh.push_back(mat[(i+1)%NCOL][(j+1)%NCOL]);

}

}

int i;
int j;
for (i = 0; i<NCOL; i++) {
for (j = 0; j<NCOL; j++) {
mat[i][j].neigh.push_back(mat[(i-1+NCOL)%NCOL][(j-1+NCOL)%NCOL]);
//mat[i][j].neigh.push_back(mat[i][(j-1+NCOL)%NCOL]);
mat[i][j].neigh.push_back(mat[(i+1)%NCOL][(j-1+NCOL)%NCOL]);
mat[i][j].neigh.push_back(mat[(i-1+NCOL)%NCOL][j]);
mat[i][j].neigh.push_back(mat[(i+1)%NCOL][j]);
mat[i][j].neigh.push_back(mat[(i-1+NCOL)%NCOL][(j+1)%NCOL]);
mat[i][j].neigh.push_back(mat[i][(j+1)%NCOL]);
mat[i][j].neigh.push_back(mat[(i+1)%NCOL][(j+1)%NCOL]);
}
}

*To copy to clipboard, switch view to plain text mode *

Now, with this piece of code the project runs fine, however when I uncomment the second line of the loop, the project won't run...

Sometimes, it crashes imediately, sometimes it says in the application output that the app is starting and it just stays that way until I force quit it, I had both error 1 and error 3 and for twice now I had my pc restarting while waiting for the mainwindow to show up. I even had those errors claiming I don't have permission.

I really do not understand what is going on here

I realized that when trying to run the app with the uncommented line, qt takes about 90% of my computer memory, but I don't know if this is part of the problem since a little line of code should not be such a problem.

I would really appreciate if anyone knows what is happening as I cannot advance in my project until I solve this problem.

## Bookmarks