I want to screen scrape the image from a GLUT window that has been rendered in OpenGL. In side of the display callback I inserted this code:
display() {
drawTriangle(); //Renders the image
if(shouldDisplay) {
shouldDisplay=0;
bytes = width*height*3; //Color space is RGB
buffer = (GLubyte *)malloc(bytes); //buffer is global var for now
glFinish();
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, buffer);
}
glutSwapBuffers();
}
After this code runs, malloc starts failing. It fails with ENOMEM, error 12. I don’t know enough about operating systems or GLUT to understand why this is happening. I’m only trying to allocate 17K on a machine with 3 GB. I’m using Windows XP and Visual Studio C++ 2010 Express. Any help or suggestions is appreciated.
That code misses a
free(buffer)at the end, so with each redraw more and more memory is consumed until the process runs out of memory and/or address space (the later only on a 32 bit system, since 64 bits of address space are hardly to exhaust with small allocations in a reasonable time).