Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: c++ Winapi handles grows up to 1800 with pixelformatdescriptor

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2013
    Posts
    11

    c++ Winapi handles grows up to 1800 with pixelformatdescriptor

    Hello guys, I have one serious problem with pixelformatdescriptor
    ...
    static PIXELFORMATDESCRIPTOR pfd =
    {
    sizeof(PIXELFORMATDESCRIPTOR),
    1,
    PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
    PFD_TYPE_RGBA,
    32,
    0, 0, 0, 0, 0, 0,
    0,
    0,
    0,
    0, 0, 0, 0,
    32,
    0,
    0,
    PFD_MAIN_PLANE,
    0,
    0, 0, 0
    };

    if(!(hdc = GetDC(hwnd))) // Did We Get A Device Context?
    {
    KillGLWindow(); // Reset The Display
    ShowCursor(true);
    MessageBox(NULL, "Can't Create A GL Device Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
    return FALSE; // Return FALSE
    }
    //DescribePixelFormat(hdc, PixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
    // 650 handles
    if(!(PixelFormat = ChoosePixelFormat(hdc, &pfd))) // Did Windows Find A Matching Pixel Format?
    {
    KillGLWindow(); // Reset The Display
    ShowCursor(true);
    MessageBox(NULL, "Can't Find A Suitable PixelFormat.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
    return FALSE; // Return FALSE
    }
    // + another 1100 handles
    if(!SetPixelFormat(hdc, PixelFormat, &pfd)) // Are We Able To Set The Pixel Format?
    {
    KillGLWindow(); // Reset The Display
    ShowCursor(true);
    MessageBox(NULL, "Can't Set The PixelFormat.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
    return FALSE; // Return FALSE
    }
    if(!(hRC = wglCreateContext(hdc))) // Are We Able To Get A Rendering Context?
    {
    KillGLWindow(); // Reset The Display
    ShowCursor(true);
    MessageBox(NULL, "Can't Create A GL Rendering Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
    return FALSE; // Return FALSE
    }
    if(!wglMakeCurrent(hdc, hRC)) // Try To Activate The Rendering Context
    {
    KillGLWindow(); // Reset The Display
    ShowCursor(true);
    MessageBox(NULL, "Can't Activate The GL Rendering Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
    return FALSE; // Return FALSE
    }
    if(!InitGL()) // Initialize Our Newly Created GL Window
    {
    KillGLWindow(); // Reset The Display
    ShowCursor(true);
    MessageBox(NULL, "Initialization Failed.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
    return FALSE; // Return FALSE
    }
    ....


    Everything works like a charm but one thing. Handles of the application radicaly increase once I ChoosePixelFormat - handles in TaskMgr grow up to 650 handles and after wglCreateContext it increases of another 1100 handles, so my app ends up with something around 1800 handles. My question is simple, is that radical handle increase normal?
    Thank you all in advance

  2. #2
    Junior Member Regular Contributor Agent D's Avatar
    Join Date
    Sep 2011
    Location
    Innsbruck, Austria
    Posts
    153
    What version of Windows(R) and what graphics hardware/driver are you using? In my experience, some graphics drivers are extremely resource wastefull when creating GL contexts.
    I just tried two small sample programs on a virtualBox virtual XP machine and the task manager indicated some 43 handles.

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2013
    Posts
    11
    Thank you for a quick reply.
    I am runing on Windows 8 and on AMD Radeon HD7770 VaporX GPU with the latest 14.100.0.0 driver. My collegue has the same problem with Windows 8.1 on AMD Radeon as well.

  4. #4
    Junior Member Regular Contributor Agent D's Avatar
    Join Date
    Sep 2011
    Location
    Innsbruck, Austria
    Posts
    153
    I guess that's typicall for AMD. The last time I tested glX and xrender programs on a CentOS system with the proprietary AMD driver I noticed that they consumed and leaked quite a lot of memory.

  5. #5
    Junior Member Regular Contributor
    Join Date
    Nov 2012
    Location
    Bremen, Germany
    Posts
    167
    Do you actually have a real problem or do you just wonder there are so many handles?

  6. #6
    Junior Member Newbie
    Join Date
    Aug 2013
    Posts
    11
    I am just wondering, why the pixelformatdescriptor takes so many handles...it seems really weird to me...

  7. #7
    Junior Member Newbie
    Join Date
    Aug 2013
    Posts
    11
    So when I run the app on nVidia GPU, it won't take so many handles?

  8. #8
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,217
    I honestly think you're just being paranoid counting handles like this. On a test app, using Windows 8.1, I get ~20,000 handles in use during normal operation with just Firefox, Visual Studio and a File Explorer window open.

    There are plenty of reasons why Windows, a driver or an app might create additional handles and they're not necessarily all related to being "wasteful" or leaking resources.

    A HANDLE is just a generic data type used by many Windows API calls; MSDN defines the following object types that may use one (I'm using an older version of MSDN here so doubtless the list has since grown):

    - Accelerator tables.
    - Bitmaps.
    - Brushes.
    - Color spaces.
    - DDE stuff.
    - Device contexts.
    - The desktop.
    - Drag and drop.
    - Window positioning.
    - Metafiles.
    - Fonts.
    - GDI objects.
    - Global memory blocks.
    - Hooks.
    - Icons.
    - Program instances.
    - Registry keys.
    - Local memory blocks.
    - Etc etc etc.

    If you look at http://blogs.technet.com/b/markrussi...9/3283844.aspx you'll see that you can create ~16,000,000 handles on both 32-bit and 64-bit Windows before you exhaust resources, so unless you have actual evidence of a real leak (i.e the handle count constantly rising until something crashes) then you really don't need to worry about it (I can virtually guarantee that you're nowhere near that limit), and the problem is definitely not as serious as you think (I'd actually argue as to whether or not it's even a "problem").

  9. #9
    Junior Member Newbie
    Join Date
    Aug 2013
    Posts
    11
    Ok, thank you very much!
    I was just wondering about it becouse most modern games don't have even a third of what my app has. Not a serious problem, once again, thank you and have a nice day

  10. #10
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,217
    Most modern games use Direct3D, not OpenGL, so you're not really comparing like-with-like.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •