#141 glutGet(GLUT_DISPLAY_MODE_POSSIBLE) crashes

closed-fixed
nobody
None
5
2011-01-25
2010-11-08
No

glutGet(GLUT_DISPLAY_MODE_POSSIBLE) crashes because it calls fgSetupPixelFormat with a null current window pointer.

I rewrote fgSetupPixelFormat to fix this. The difference is that it creates a device context if the format is being checked instead of setup.

GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
unsigned char layer_type )
{
#if defined(_WIN32_WCE)
return GL_TRUE;
#else
PIXELFORMATDESCRIPTOR pfd;
PIXELFORMATDESCRIPTOR* ppfd = &pfd;
int pixelformat;
HDC current_hDC;
GLboolean success;

if (checkOnly)
current_hDC = CreateDC(TEXT("DISPLAY"), NULL ,NULL ,NULL);
else
current_hDC = window->Window.Device;

fghFillPFD( ppfd, current_hDC, layer_type );
pixelformat = ChoosePixelFormat( current_hDC, ppfd );

/* windows hack for multisampling/sRGB */
if ( ( fgState.DisplayMode & GLUT_MULTISAMPLE ) ||
( fgState.DisplayMode & GLUT_SRGB ) )
{
HGLRC rc, rc_before=wglGetCurrentContext();
HWND hWnd;
HDC hDC, hDC_before=wglGetCurrentDC();
WNDCLASS wndCls;

/* create a dummy window */
ZeroMemory(&wndCls, sizeof(wndCls));
wndCls.lpfnWndProc = DefWindowProc;
wndCls.hInstance = fgDisplay.Instance;
wndCls.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
wndCls.lpszClassName = _T("FREEGLUT_dummy");
RegisterClass( &wndCls );

hWnd=CreateWindow(_T("FREEGLUT_dummy"), _T(""), WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW , 0,0,0,0, 0, 0, fgDisplay.Instance, 0 );
hDC=GetDC(hWnd);
SetPixelFormat( hDC, pixelformat, ppfd );

rc = wglCreateContext( hDC );
wglMakeCurrent(hDC, rc);

if ( fghIsExtensionSupported( hDC, "WGL_ARB_multisample" ) )
{
PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARBProc =
(PFNWGLCHOOSEPIXELFORMATARBPROC) wglGetProcAddress("wglChoosePixelFormatARB");
if ( wglChoosePixelFormatARBProc )
{
int attributes[100];
int iPixelFormat;
BOOL bValid;
float fAttributes[] = { 0, 0 };
UINT numFormats;
fghFillPixelFormatAttributes( attributes, ppfd );
bValid = wglChoosePixelFormatARBProc(hDC, attributes, fAttributes, 1, &iPixelFormat, &numFormats);

if ( bValid && numFormats > 0 )
{
pixelformat = iPixelFormat;
}
}
}

wglMakeCurrent( hDC_before, rc_before);
wglDeleteContext(rc);
ReleaseDC(hWnd, hDC);
DestroyWindow(hWnd);
UnregisterClass(_T("FREEGLUT_dummy"), fgDisplay.Instance);
}

success = ( pixelformat != 0 ) && ( checkOnly || SetPixelFormat( current_hDC, pixelformat, ppfd ) );

if (checkOnly)
DeleteDC(current_hDC);

return success;
#endif /* defined(_WIN32_WCE) */
}
#endif /* TARGET_HOST_MS_WINDOWS */

Discussion

  • Nigel Stewart

    Nigel Stewart - 2010-11-10

    Could you attach the modified source file to this bug also? Pasting into the description messes up the formatting, unfortunately.

     
  • John F. Fay

    John F. Fay - 2011-01-25

    Fixed at revision 889.

     
  • John F. Fay

    John F. Fay - 2011-01-25
    • status: open --> closed-fixed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks