Sign in to follow this  
hallgeir

OpenGL ChoosePixelFormat() gives an "unhandled exception"

Recommended Posts

Hi. Something strange happened. Up until (and including) last night it seemed my code worked great. When I started up visual studio today and tried to run my game, I got an unhandled exception error message. I started digging, and found the line that gave me the error. It was the call to the function ChoosePixelFormat in my opengl initialization code. Here's my call to the ChoosePixelFormat function: p_nPixelFormatID = ChoosePixelFormat(m_hDC, &p_pfPixelFormat); And here's what I do know: - m_hDC is a valid HDC (I have tested it by calling TextOut to write to it, and the correct text appears in the correct position). - It worked yesterday, but not today even though I didn't make any changes in my code. - I've tried calling ChoosePixelFormat right after I create my window, in the very beginning of the program to see if there's some bad code that messes things up (the answer was negative - I still got the same error). - The window handle that I passed to the GetDC() function to get the HDC is valid. - Here's the full error message: Unhandled exception at 0x69736a3d in Game.exe: 0xC0000005: Access violation reading location 0x000000a3. I did however install Windows Vista here the other day, and although the code did run on Vista yesterday, might there be a compatibility problem between Vista and Visual studio 2005 that is causing it? Also I'm wondering: Is ChoosePixelFormat a part of the Windows OpenGL library, or is it a Win32 API function? If it's the first one maybe I should try finding some other OpenGL library? Currently I'm using the OpenGL headers and .lib files included in VS2005. If I don't find any solution to this problem I'll probably try setting up OpenGL with SDL instead.. Edit: I forgot some information that might be useful. If I pass "NULL" to the ChoosePixelFormat function instead of m_hDC, I get no error message. Also if I create a new HDC with CreateDC(), I also get no error message... /ponders Thanks in advance for any help on this very annoying matter.

Share this post


Link to post
Share on other sites
Sup man,

Hmmm... It's most likely has something to do w/OpenGL and Vista compatiblity issues. As for the ChoosePixelFormat function, it is part of the old Win32 GDI functionality ( which might explain those issues ). Did you change any fields in the PIXELFORMATDESCRIPTOR instance? If not, maybe it'd be worth changing some of them around ( particually the iLayerType & dwFlags members ) to see if it changes anything...

Peace,

ahayweh

Share this post


Link to post
Share on other sites
Quote:
Original post by ahayweh
Sup man,

Hmmm... It's most likely has something to do w/OpenGL and Vista compatiblity issues. As for the ChoosePixelFormat function, it is part of the old Win32 GDI functionality ( which might explain those issues ). Did you change any fields in the PIXELFORMATDESCRIPTOR instance? If not, maybe it'd be worth changing some of them around ( particually the iLayerType & dwFlags members ) to see if it changes anything...

Peace,

ahayweh


Thanks for the reply.

I didn't change anything at all in the initialization code. After I read your post I did try changing the dwFlags member. I removed one by one flag, tried different combinations, tried no flags at all but I get the same error. According to the Visual Studio documentation on the PIXELFORMATDESCRIPTOR structure, iLayerType is ignored:
"iLayerType
Ignored. Earlier implementations of OpenGL used this member, but it is no longer used."

I tried setting it to 0 to see if it changed anything (it was set to PFD_MAIN_PLANE earlier), but unfortunately I got the same results :(

Thanks for trying.. :)

Share this post


Link to post
Share on other sites
This is getting plain silly.

I now tried to set up SDL to try using that instead, and the function "SDL_SetVideoMode" gives me the EXACT same error. I'm guessing that function calls ChoosePixelFormat, and it fails... /sigh

/considers reinstalling WinXP.

Edit: And there I found the error. It's my graphics drivers... I used the whole yesterday to find working drivers for my Geforce 7800GT card (all the new ones wouldn't let me run on higher resolutions than 1024x768), so I found some older drivers. Obviously they didn't work as well as they should...

Windows XP here I come! :P

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this