I have a block of code that does something with this:
int pieceX = 0; int pieceY = 0; int board[8][47] = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}; if (pieceX > 0 && pieceY < 46) { /* If I remove this it doesn't crash */ if (board[pieceX-1][pieceY] == 0 && board[pieceX][pieceY+1] == 0) { pieceX -= 1; } /*-----------------------------------*/ }
As far as I can tell, I initialize my array correctly and I stay within the index. I do not work very much on processing or Arduino, so I hope it will be something simple / obvious.
Edit: Hmm .. I just did a minimalistic test version with this code, and it doesn't crash. So, this is somehow related to the code not in this example. Heck. Go to try setting zero on these lines. (I feel bad for posting this question before correctly isolating the problem code.) Although this accurately describes the problem, it does not reproduce it. A strange mistake.
Edit 2: this is not a failure:
if (buttonA == HIGH) { if (pieceX > 0 && pieceX < 8 && pieceY > 0 && pieceY < 46) { if (board[0][0] == 0) { } } }
This is not a failure:
if (buttonA == HIGH) { if (pieceX > 0 && pieceX < 8 && pieceY > 0 && pieceY < 46) { pieceX -= 1; } }
This is a failure:
if (buttonA == HIGH) { if (pieceX > 0 && pieceX < 8 && pieceY > 0 && pieceY < 46) { if (board[0][0] == 0) { pieceX -= 1; } } }
Any idea what is going on? ButtonA is never HIGH, so the code I configure should not matter (all of this checks and loads in order.)
Edit 3: This leads to crashes:
if (buttonA == HIGH) { if (pieceX > 0 && pieceX < 8 && pieceY > 0 && pieceY < 46) { if (board[0][0] == 0) { pieceX -= 1; } } }
Is not:
if (0 == 1) { if (pieceX > 0 && pieceX < 8 && pieceY > 0 && pieceY < 46) { if (board[0][0] == 0) { pieceX -= 1; } } }
Failure:
if (buttonA == HIGH) { if (pieceX > 0 && pieceX < 8 && pieceY > 0 && pieceY < 46) { if (board[0][0] == 0) { pieceX = 1; } } }
Is not:
if (buttonA == HIGH) { if (pieceX > 0 && pieceX < 8 && pieceY > 0 && pieceY < 46) { pieceX = 1; } }
AND THIS IS NOT:
if (buttonA == HIGH) { if (pieceX > 0 && pieceX < 8 && pieceY > 0 && pieceY < 46) { if (board[0][0] == 0) { } } }
Edit, here is the full source code. I am only a few hours at Dr. Mario's black and white doctor. I never write in this language, therefore .. potentially a bit messy. A more random training experiment in processing / video game / arduino equipment.