Xcode crashes on multidimensional bool array (bool[,,])

I’ve got a project which uses a 3-dimensional boolean array, which runs fine in the editor. But once I port it to an iPad (through xCode) I get a “Random” crash on a valid index. Details: through debugging, I’ve gotten it down to the last line here:

bool A[,,] = new bool[2,3,3];

A[0,0,0]=false; // fine, editor and Xcode
A[0,1,2]=false; // fine up to here

A[0,2,0]=false; // fine in editor, functionally tested
//  Crashes xCode/iPad:  out-of-range-exception

Running Unity4.5 with xCode 5.1

…and I’m answering my own Q:

1 Answer

1

It seems to be a glitch. xCode (through Unity? not sure what step is wrong) just doesn’t like 3-dimensional bool[,,] and messes up the indexes somehow. Switching to simply bool[,] completely solved the problem (of course, have to redo the logic a little.)

In my case, I had a 2-level board, using A[level, row, col]. So had to switch from A[2,3,3] by combining row and col to A[2,9] then using A[level, row*3+col] for the lookups (instead of A[level, row, col];)