Banging my head for 1 hour, can't find the answer:
int *get_possible_moves(int **board, int *w, int *h, int *x, int *y) {
int movespossible=0;
int moveslist[2][8];
//4
if(x + 1 <= w-1 && y + 2 <= h - 1) {
if(board[*(int *)y + 2][*(int *)x + 1] == 0) {
moveslist[movespossible][0] = *(int *)x + 1;
breakpoint-> moveslist[movespossible][1] = *(int *)y开发者_开发问答 + 2;
movespossible++;
}
}
At a line marked breakpoint-> my **board gets dereferenced. Any clues why it is so? There are no concurrent threads that are using this place in memory. Also, I am not using **board at all at this line.
//3
if(x + 2 <= w - 1 && y + 1 <= h - 1) {
if(board[*(int *)y + 1][*(int *)x + 2] == 0) {
moveslist[movespossible][0] = *(int *)x + 2;
moveslist[movespossible][1] = *(int *)y + 1;
movespossible++;
}
}
This code works flawlessly.
Thanks in advance!
You have:
int moveslist[2][8];
... yet you often reference it:
moveslist[movespossible][0]
moveslist[movespossible][1]
... shouldn't you do it:
moveslist[0][movespossible]
moveslist[1][movespossible]
?
OKay, got it. Array out of bounds.
It quickly happens when movespossible++
is done twice.
When array gets out of bounds, it goes on to travel in random memory space, eventually hitting board.
精彩评论