0

I'm writing a c code in Xilinx SDK for microblaze. The variables were defined as:

int xcoi;
int ycoi;
u16 mat[1280][720];

The code reads the image data stored in DDR2 memory and saves it into a variable.

if ((lBtnChanges & bitBtnD) && (lBtnStateNew & bitBtnD))
    {
        for(xcoi = 0; xcoi<1280; xcoi++)
        {
            for(ycoi = 0; ycoi<720; ycoi++)
            {
                mat[xcoi][ycoi] = Xil_In16(pFrame + ycoi*(lLineStride*2) + xcoi*2);
                xil_printf("\n\r xcoi = %d    ycoi = %d \n\r",xcoi,ycoi);
            }

        }
    }

To check whether code is working properly, I have printed the x and y coordinated in the console. The part of output where I get error is:

xcoi = 11 ycoi = 253

xcoi = 11 ycoi = 254

xcoi = 11 ycoi = 255

xcoi = 11 ycoi = 256

xcoi = 11 ycoi = 257

xcoi = 11 ycoi = 258

xcoi = 11 ycoi = 259

xcoi = 11 ycoi = 260

xcoi = -547553269 ycoi = 261

xcoi = -547553269 ycoi = 262

xcoi = -547553269 ycoi = 263

xcoi = -547553269 ycoi = 264

xcoi = -547553269 ycoi = 265

xcoi = -547553269 ycoi = 266

xcoi = -547553269 ycoi = 267

Why does xcoi change after xcoi = 11 ycoi = 260? Instead it should be xcoi = 11 ycoi = 261 in the next line.

monika
  • 1
  • 2
  • 1
    What is the values of `xcoFrameMax` and `ycoFrameMax`? If they're smaller than `1280` and `720` (respectively) you will go out of bounds of the `mat` array and have *undefined behavior*. – Some programmer dude Apr 22 '16 at 04:51
  • If you're allocating mat on stack, try to move it into globals just to make sure you don't have a stack overflow. – dkz Apr 22 '16 at 18:36
  • I made mat global and problem was solved. Thank You! – monika May 02 '16 at 05:13

0 Answers0