I have this recursive function that segfaults in a bizarre way.
void Main::surroundCheck(int x, int y) {
if (x < 0 || y < 0 || x >= 16 || y >= 16) {
return;
}
go_board[x][y]->setState(4);
Main::surroundCheck(x + 1,y);
Main::surroundCheck(x - 1,y);
Main::surroundCheck(x,y + 1);
Main::surroundCheck(x,y - 1);
}
go_board is a two dimensional array of objects that are subclasses of Sprite and they have a state which i am now trying to alter. With the following code i could just use a for loop to change all tiles to state 4 but i need to use this method because i will later add functionality that requires the use of this kind of function. I call this function with the following line from a function called onTouchBegan() which is called by a touch event listener:
this->surroundCheck(3,3);
I am very puzzled by this because i have used a similar function before in my other project and it worked fine.