ReadPixel 'odd' framebuffer sizes throws memory exceptions

Hi,

I’m trying to read pixels from an offscreen framebuffer.
For the most part all works fine.

However when certain sizes of the frame buffer opengl (or in my case openTK) throws memory errors not being able to read out the memory.
It seems that for the larger pixel sizes mostly with odd sizes this happens.

91x91: ok
911x911: ok
1501x1501: exception
1501x1500: ok
2121x2121: exception
2122x2122: exception
3620x3620: ok

It seems opengl is drawing fine.
There are no opengl errors thrown.

But the exception is thrown when calling ReadPixels with above sizes.

My question; is there any limitation on ReadPixels that i’m not seeing?
Should for ReadPixels to work there be a multiple of 2 or 4 inside the sizing? and why?

Are you changing the pack alignment to 1?

Have you verified that the pointer to the buffer you’re providing will hold that much data?

Hi Dark Photon,

Thanks! The pack alignment setting works! It was indeed this problem.

However; in the further processing of the images in .NET it seems to generate the same problem.
Trying to store it as an 8bitperpixel Bitmap yields similar strange exceptions when the with is not a multiple of 4.

So i decided to stick with a multiple of 4 for now.
(it has speed benefits compared to doing 32bits readpixels and storing those images)

The BMP format requires row width to be a multiple of 4 bytes.