Note that there are some explanatory texts on larger screens.

plurals
  1. POArduino multi-dimensional array crash
    primarykey
    data
    text
    <p>I have a block of code that does something to this effect:</p> <pre><code>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 &gt; 0 &amp;&amp; pieceY &lt; 46) { /* If I remove this it doesn't crash */ if (board[pieceX-1][pieceY] == 0 &amp;&amp; board[pieceX][pieceY+1] == 0) { pieceX -= 1; } /*-----------------------------------*/ } </code></pre> <p>As far as I can tell, I'm initializing my array correctly and I'm staying within the index bounds. I don't work much with Processing or Arduino, so I'm hoping it's something simple / obvious.</p> <p>Edit: Hmm.. I just made a minimalistic test version with this code, and it doesn't crash. So, it's something to do with the code not in this example. Damn. Going to try to zero in on those lines. (My bad for posting this before properly isolating the problem code.) While this accurately describes the problem, it does not reproduce it. Strange bug.</p> <p>Edit 2: This doesn't crash:</p> <pre><code>if (buttonA == HIGH) { if (pieceX &gt; 0 &amp;&amp; pieceX &lt; 8 &amp;&amp; pieceY &gt; 0 &amp;&amp; pieceY &lt; 46) { if (board[0][0] == 0) { } } } </code></pre> <p>This doesn't crash:</p> <pre><code>if (buttonA == HIGH) { if (pieceX &gt; 0 &amp;&amp; pieceX &lt; 8 &amp;&amp; pieceY &gt; 0 &amp;&amp; pieceY &lt; 46) { pieceX -= 1; } } </code></pre> <p>This DOES crash:</p> <pre><code>if (buttonA == HIGH) { if (pieceX &gt; 0 &amp;&amp; pieceX &lt; 8 &amp;&amp; pieceY &gt; 0 &amp;&amp; pieceY &lt; 46) { if (board[0][0] == 0) { pieceX -= 1; } } } </code></pre> <p>Any idea what's going on? ButtonA is never HIGH, so.. the code I'm tweaking shouldn't even matter (it all verifies and uploads fine.)</p> <p>Edit 3: This crashes:</p> <pre><code>if (buttonA == HIGH) { if (pieceX &gt; 0 &amp;&amp; pieceX &lt; 8 &amp;&amp; pieceY &gt; 0 &amp;&amp; pieceY &lt; 46) { if (board[0][0] == 0) { pieceX -= 1; } } } </code></pre> <p>This DOES NOT:</p> <pre><code>if (0 == 1) { if (pieceX &gt; 0 &amp;&amp; pieceX &lt; 8 &amp;&amp; pieceY &gt; 0 &amp;&amp; pieceY &lt; 46) { if (board[0][0] == 0) { pieceX -= 1; } } } </code></pre> <p>This crashes:</p> <pre><code>if (buttonA == HIGH) { if (pieceX &gt; 0 &amp;&amp; pieceX &lt; 8 &amp;&amp; pieceY &gt; 0 &amp;&amp; pieceY &lt; 46) { if (board[0][0] == 0) { pieceX = 1; } } } </code></pre> <p>This DOES NOT:</p> <pre><code>if (buttonA == HIGH) { if (pieceX &gt; 0 &amp;&amp; pieceX &lt; 8 &amp;&amp; pieceY &gt; 0 &amp;&amp; pieceY &lt; 46) { pieceX = 1; } } </code></pre> <p>AND THIS DOES NOT:</p> <pre><code>if (buttonA == HIGH) { if (pieceX &gt; 0 &amp;&amp; pieceX &lt; 8 &amp;&amp; pieceY &gt; 0 &amp;&amp; pieceY &lt; 46) { if (board[0][0] == 0) { } } } </code></pre> <p>Edit, <a href="http://pastebin.com/LtcAQ97z" rel="nofollow">here</a>'s the full source code. I'm only a few hours into a black and white Dr Mario clone. I never write in this language, so.. potentially a bit sloppy. More of a random learning experiment in processing / video game hardware / arduino.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload