1

I am trying to use glReadPixels() to read a window of 5 * 5 pixels. Here is the code.

const unsigned int WINDOW_SIZE = 5;
const unsigned int NB_COMPONENTS = 3;
GLubyte array[NB_COMPONENTS * WINDOW_SIZE * WINDOW_SIZE];
glReadPixels( 0, 0, WINDOW_SIZE, WINDOW_SIZE, GL_RGB, GL_UNSIGNED_BYTE, array);

Yet this code causes the following error in visual studio: "Stack around variable array was corrupted"

If I add +4 to the size of the array it works fine. Does someone knows why?

Milo
  • 145
  • 1
  • 7

1 Answers1

1

Since you're using GL_RGB make sure GL_PACK_ALIGNMENT is set to 1.

genpfault
  • 51,148
  • 11
  • 85
  • 139