i have a screenshot routine with glreadpixels.
strange behaviour:
- crash if window is resized horizontally
- no crash if window is not resized
- no crash if window is resized vertically
- no crash in any fullscreen mode
the routine crashes at the glReadPixels call, if (0, 0 changed to (1, 1 then everything works fine
so buffer overflow ? I made the buffer bigger, no change.
any1 ?
// write screenshot to disk
void GLTools::screenShot(int width, int height) {
printf(“GLTools::screenShot(): writing screenshot.tga (%dx%d) to disk…
“, width, height);
// allocate buffer and calculate buffer size
unsigned char *buffer;
int bufsize = width * height * 3 + 18;
buffer = (unsigned char *) malloc(bufsize);
if (buffer != NULL) {
// write tga header
memset(buffer, 0, 18);
buffer[2] = 2;
buffer[12] = width & 255;
buffer[13] = width >> 8;
buffer[14] = height & 255;
buffer[15] = height >> 8;
buffer[16] = 24;
// read pixels
glReadPixels(0, 0, width, height, GL_BGR_EXT, GL_UNSIGNED_BYTE, buffer + 18);
// write to file
FILE * pFile;
pFile = fopen(“screenshot.tga” , “w”);
if (pFile != NULL) {
fwrite (buffer, 1, bufsize, pFile);
fclose (pFile);
}
else {
// fopen() failed
printf(” *** Error: GLTools::screenShot(): fopen() failed”);
exit(1);
}
free (buffer);
}
else {
// malloc() failed
printf(" *** Error: GLTools::screenShot(): malloc() failed");
exit(1);
}
}