wierd memory error.

i know it has nothing to do with opengl, but i dont see why not asking it here.
im reading from the frame buffer using the glReadPixels() function. now, i allocate memory for the pointer that will contain the color values like that-
unsigned char p*=new unsigned char[3widthheight];
i read what i need to read from it, and than delete it like that-
delete[] p;
nothing fancy, it works, the problem is that it works only a few times, and than it stops working, until i rebot the computer, it does a run-time error, that occurs when i delete the array, i traced into the assambly code of the delete operator, and the error is in the line
call rg_free
or something like that, im not sure about the rg_.
i really cant find the problem, im doing nothing special, just new and than delete.
any ideas for the couse of the problem?

unsigned char p*=new unsigned char[3widthheight];

Does the glReadPixels return the results you were expecting? It seems that perhaps you have the wrong bit depth, maybe it’s actually 32-bit instead of 24-bit. Or it might be aligned like the 32-bit aligned windows bitmaps in which case you’d need a larger buffer if your width isn’t a multiple of 4.

[This message has been edited by danoon (edited 02-14-2001).]

well, maybe, but i know this - i changed the unpack alignment to 1 with glStorePixel(), so it supposed to store that in a 3 byte sequences of r g b and not using this empty byte, i mean using 24 bit and not 32 bit.
so thats not supposed to be the problem, the value are correct, and no rror occures when calling the glReadPixels() function.

For ReadPixels, you need to change the PACK_ALIGNMENT, not the UNPACK_ALIGNMENT, to 1.

  • Matt

thank you very much, it works, it seems i was misleaded , i have been told to use unpack.