processing - Arduino multi-dimensional array crash -
i have block of code effect:
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 remove doesn't crash */ if (board[piecex-1][piecey] == 0 && board[piecex][piecey+1] == 0) { piecex -= 1; } /*-----------------------------------*/ }
as far can tell, i'm initializing array correctly , i'm staying within index bounds. don't work processing or arduino, i'm hoping it's simple / obvious.
edit: hmm.. made minimalistic test version code, , doesn't crash. so, it's code not in example. damn. going try 0 in on lines. (my bad posting before isolating problem code.) while accurately describes problem, not reproduce it. strange bug.
edit 2: doesn't crash:
if (buttona == high) { if (piecex > 0 && piecex < 8 && piecey > 0 && piecey < 46) { if (board[0][0] == 0) { } } }
this doesn't crash:
if (buttona == high) { if (piecex > 0 && piecex < 8 && piecey > 0 && piecey < 46) { piecex -= 1; } }
this crash:
if (buttona == high) { if (piecex > 0 && piecex < 8 && piecey > 0 && piecey < 46) { if (board[0][0] == 0) { piecex -= 1; } } }
any idea what's going on? buttona never high, so.. code i'm tweaking shouldn't matter (it verifies , uploads fine.)
edit 3: crashes:
if (buttona == high) { if (piecex > 0 && piecex < 8 && piecey > 0 && piecey < 46) { if (board[0][0] == 0) { piecex -= 1; } } }
this not:
if (0 == 1) { if (piecex > 0 && piecex < 8 && piecey > 0 && piecey < 46) { if (board[0][0] == 0) { piecex -= 1; } } }
this crashes:
if (buttona == high) { if (piecex > 0 && piecex < 8 && piecey > 0 && piecey < 46) { if (board[0][0] == 0) { piecex = 1; } } }
this not:
if (buttona == high) { if (piecex > 0 && piecex < 8 && piecey > 0 && piecey < 46) { piecex = 1; } }
and not:
if (buttona == high) { if (piecex > 0 && piecex < 8 && piecey > 0 && piecey < 46) { if (board[0][0] == 0) { } } }
edit, here's full source code. i'm few hours black , white dr mario clone. never write in language, so.. potentially bit sloppy. more of random learning experiment in processing / video game hardware / arduino.
this looks running out of memory.
int board[8][47]
consumes 752 bytes of memory. in addition
tv.begin(ntsc,120,96);
will call
char tvout::begin(uint8_t mode, uint8_t x, uint8_t y) { // check if x divisable 8 if ( !(x & 0xf8)) return 1; x = x/8; screen = (unsigned char*)malloc(x * y * sizeof(unsigned char));
which tries allocate 1440 bytes of memory. 1440 + 752 == 2192 > 2048 == sram size of arduino
so running out of memory.
can switch int board[8][47] int int8_t or uint8_t? reduce memory consumption of array 2. still tight on memory.
Comments
Post a Comment