RLP array passing help - crashing firmware?

Hello, I am having some problems with an RLP call that I am making causing the board (FEZCobraIII) to crash. Stepping through the app, it just hangs and then stops when the RLP function is called. I can no longer talk to the board, and to recover I have to go through a “Loader (TinyBooter) Update” process from FEZConfig.

I have isolated the failing code and made a working version. The only difference is that it fails when I try to pass in a byte[] array (of length 512). The native code that works and doesn’t work is below. Any tricks I am missing in passing an array? I am calling it synchronously so the data should not be moved by the CLR.

NOT WORKING:


typedef unsigned char byte;
/*
Sets the RGB data for an entire matrix
*/
void PushRgbMatrix(void** args)
{
    byte* rowData = (byte*)(args[1]);
    int row,col;
    byte pinStates;
    for(row=0; row<16; row++)
    {
        RLP->GPIO.Writepin(_pRow[0], (row & 0x01));
        RLP->GPIO.Writepin(_pRow[1], (row & 0x02) >> 1);
        RLP->GPIO.Writepin(_pRow[2], (row & 0x04) >> 2);
        RLP->GPIO.Writepin(_pRow[3], (row & (4+4)) >> 3); //don't comment on this--the forum formatter didn't like the hex eight
        RLP->GPIO.Writepin(_pOE, 0);
        for(col=0; col<32; col++)
        {
            pinStates = rowData[(row * 32) + col];            
            RLP->GPIO.Writepin(_pRgb1[0], (pinStates & 0x01));       //R1
            RLP->GPIO.Writepin(_pRgb1[1], (pinStates & 0x02) >> 1);  //G1
            RLP->GPIO.Writepin(_pRgb1[2], (pinStates & 0x04) >> 2);  //B1
            RLP->GPIO.Writepin(_pRgb2[0], (pinStates & 0x08) >> 3);  //R2
            RLP->GPIO.Writepin(_pRgb2[1], (pinStates & 0x10) >> 4);  //G2
            RLP->GPIO.Writepin(_pRgb2[2], (pinStates & 0x20) >> 5);  //B2
            RLP->GPIO.Writepin(_pClock, 1);
            RLP->GPIO.Writepin(_pClock, 0);
        }
        RLP->GPIO.Writepin(_pLatch, 1);
        RLP->GPIO.Writepin(_pLatch, 0);
    }

}

C# calling code

_driver.PushRgbMatrix(_canvas.Buffer);
//Where _canvas.Buffer is a property returning a byte[] of size 512.

WORKING:


void SetTestMatrixNoParameters(void** args)
{
    int row,col;
    byte pinStates;
    byte rowData[512];

    int i;
    for(i=0; i<512; i++)
        rowData[i] = 0x31; //some color pair

    for(row=0; row<16; row++)
    {
        RLP->GPIO.Writepin(_pOE, 1);
        RLP->GPIO.Writepin(_pRow[0], (row & 0x01));
        RLP->GPIO.Writepin(_pRow[1], (row & 0x02) >> 1);
        RLP->GPIO.Writepin(_pRow[2], (row & 0x04) >> 2);
        RLP->GPIO.Writepin(_pRow[3], (row & (4+4)) >> 3); //don't comment on this--the forum formatter didn't like the hex eight
        RLP->GPIO.Writepin(_pOE, 0);

        for(col=0; col<32; col++)
        {
            pinStates = rowData[(row * 32) + col];
            RLP->GPIO.Writepin(_pRgb1[0], (pinStates & 0x01));       //R1
            RLP->GPIO.Writepin(_pRgb1[1], (pinStates & 0x02) >> 1);  //G1
            RLP->GPIO.Writepin(_pRgb1[2], (pinStates & 0x04) >> 2);  //B1
            RLP->GPIO.Writepin(_pRgb2[0], (pinStates & 0x08) >> 3);  //R2
            RLP->GPIO.Writepin(_pRgb2[1], (pinStates & 0x10) >> 4);  //G2
            RLP->GPIO.Writepin(_pRgb2[2], (pinStates & 0x20) >> 5);  //B2
            RLP->GPIO.Writepin(_pClock, 1);
            RLP->GPIO.Writepin(_pClock, 0);
        }
        RLP->GPIO.Writepin(_pLatch, 1);
        RLP->GPIO.Writepin(_pLatch, 0);
    }
}

@ jrowe88 - Duh!!! Was referencing args[1], not [0] :-[