stefan0073

Exception in ChoosePixelFormat

Discussion created by stefan0073 on Dec 8, 2010
Latest reply on Sep 16, 2013 by glenn.coombs
Serious problems with latest drivers

All this on Win7 x64, Catalyst Version 10.11, ATI Radeon HD 4600 Series.

There's a serious problem in the latest drivers. The very first call to ChoosePixelFormat() always throws an exception. Subsequent calls succeed without problems.

 

While the thrown exception is caught (by the driver itself, I assume), on Win7 x64 this breaks applications. See here for why this is very, very bad:

http://support.microsoft.com/kb/976038

 

Because of the exception getting caught by Windows, my window creation function never finishes because all code after ChoosePixelFormat() isn't run, so SetPixelFormat() isn't called either.

 

To reproduce the exception:

  • start Visual Studio (I'm using VS2010), Menu Debug->Exceptions, check all exceptions there
  • create a new win32 project with the default options
  • add a new menu entry to the main menu resources named "ChoosePixelFormat"

Then change the WndProc function to:

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int wmId, wmEvent;
    PAINTSTRUCT ps;
    HDC hdc;

    switch (message)
    {
    case WM_COMMAND:
        wmId    = LOWORD(wParam);
        wmEvent = HIWORD(wParam);
        // Parse the menu selections:
        switch (wmId)
        {
        case IDM_ABOUT:
            DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
            break;
        case IDM_EXIT:
            DestroyWindow(hWnd);
            break;
        case ID_FILE_CHOOSEPIXELFORMAT:
            {
                INITCOMMONCONTROLSEX InitCtrls;
                InitCtrls.dwSize = sizeof(InitCtrls);
                // Set this to include all the common control classes you want to use
                // in your application.
                InitCtrls.dwICC = ICC_WIN95_CLASSES;
                InitCommonControlsEx(&InitCtrls);

                HDC hDC = ::GetDC(hWnd);
                PIXELFORMATDESCRIPTOR pfd;
                ZeroMemory( &pfd, sizeof( pfd ) );
                pfd.nSize = sizeof( pfd );
                pfd.nVersion = 1;
                pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
                    PFD_DOUBLEBUFFER;
                pfd.iPixelType = PFD_TYPE_RGBA;
                pfd.cColorBits = 24;
                pfd.cDepthBits = 16;
                pfd.iLayerType = PFD_MAIN_PLANE;
                int iFormat = ChoosePixelFormat( hDC, &pfd );
                SetPixelFormat( hDC, iFormat, &pfd );
                ReleaseDC(hWnd, hDC);
                //DestroyWindow(hWndDummy);
            }
            break;
        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
        }
        break;
    case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);
        // TODO: Add any drawing code here...
        EndPaint(hWnd, &ps);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

 

 

Now simply execute the ChoosePixelFormat menu command and Visual Studio will get triggered because of an exception thrown by the ATI driver.

 

Of course, this is just a minor problem which I can work around (as I said: only the first call throws the exception) by calling this function before anything else gets initialized.

 

The real big problem comes if you have two monitors with two completely different graphic cards. If the window for which ChoosePixelFormat is called is not on the default monitor (the default monitor being assigned to the ATI graphics card), then ChoosePixelFormat() crashes hard every time.

 

I could attach the VS2010 test project, but the forum doesn't seem to allow attachments.

Outcomes