Results 1 to 3 of 3

Thread: glReadPixels crash

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2000

    glReadPixels crash

    I'm not sure why this is happening, but if I try to do a glReadPixels with a large screen, my program dies horribly inside OpenGL (Win32). If I cut back the size to something smaller it works fine (say 640x480). The size I'm trying to do is 1280x1024. The malloc on the pixels is working fine (I tried new and a couple of other things, but Windows is fine giving me the 1.5mb of memory I ask for). It's just glReadPixels fails if the size is too big. Anyone have any ideas? Maybe there's something extra I have to setup here before I do my screen capture? Here's the code I'm using, pretty straight forward:

    // Get the pixels from the screen
    // 640x480 works but large values like
    // 1280x1024 dont
    int w = m_ClientRect.right;
    int h = m_ClientRect.bottom;
    int imageSize = 3 * w * h;

    unsigned char *pPixelData = (unsigned char *)malloc(imageSize);

    if(pPixelData != NULL)
    // Copy from OpenGL
    glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, pPixelData);

    // Create and save the image

    // Cleanup



  2. #2

    Re: glReadPixels crash

    Well i can tell you your asking for almost 4 megs of memory not 1.5.
    What Error message does it give you? i cant help without more specifics.

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2000

    Re: glReadPixels crash

    Thanks. I figured it out by searching for another topic on glReadPixels and trying it out. Turns out that when I would use a standard size (hard coded) like 640x480 or even 1280x1024 it would work. When I used the sizes from my application, it usually crashed. I put in calls to glPixelStorei to set the alignment to 1 byte and it worked fine. Guess when I was doing it with the application window sizes, the pixels weren't aligned on the right byte boundary. Thanks.


Similar Threads

  1. How to fix crash
    By iiilyyy in forum OpenGL: User Software
    Replies: 1
    Last Post: 06-12-2013, 01:43 PM
  2. glReadPixels OR glGetTexImage crash application
    By strattonbrazil in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 09-26-2011, 06:33 PM
  3. glReadPixels() occasional Nvidia driver crash
    By speedy in forum OpenGL: Advanced Coding
    Replies: 8
    Last Post: 02-08-2008, 08:05 AM
  4. GLU crash using QT
    By in forum OpenGL: macOS
    Replies: 3
    Last Post: 10-19-2004, 05:35 AM
  5. Replies: 1
    Last Post: 09-17-2001, 01:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean