views:

182

answers:

1

Can anyone see what's wrong with this code?

SIZE_BG is 6MB as I am trying to draw a large bitmap image (3366x600). I use malloc to prevent my image from overflowing the stack. I get an access violation error on the call to glDrawPixels(). bgPtr seems to point to the correct data as I checked the first few bytes before calling glDrawPixels and they are correct.

    bgPtr = (char*)malloc(SIZE_BG);
    fstream inFile(texFileName, ios::in | ios::binary);
    inFile.read(bgPtr, SIZE_BG);
    inFile.close();

//... other code

    glDrawPixels(3366, 600, GL_BGRA_EXT, GL_UNSIGNED_BYTE, bgPtr+54);
+3  A: 

SIZE_BG is 6MB

3366 × 600 is approximately 1.92 million pixels
BRGA indicates 4 bytes per pixel
so, 3366 × 600 × 4 is just over 7.7MB

Therefore, your buffer is too small... glDrawPixels() will read past the end into unallocated memory.

Shog9
Very true. Thanks!
Tony R
@sharptooth: seems revision comments are busted, but i think i see where you were going with that edit now...
Shog9