PDA

View Full Version : Crashing out on ChoosePixelFormat



howie
01-12-2004, 07:44 AM
My simple little test app likes to crash on ChoosePixelFormat in a very random way. I can start and stop the app manytime without a problem but then other times, it crashes there a lot. This I find very wierd, any suggestions?

thanks

Relic
01-12-2004, 07:50 AM
ChoosePixelFormat has some nasty bugs, but I guess you crash somewhere later in your code?
Always call DescribePixelFormat with the id you got and check if the pixelformat really contains the required features.
Make sure your program behaves correctly if you didn't get what you wanted.

If you debug a lot on Win9x systems, sometimes the OpenGL might be "stuck". A reboot helps. NT based systems are much more robust in that manner.

howie
01-12-2004, 11:48 AM
<< ChoosePixelFormat has some nasty bugs >>

Yes it does...

<< but I guess you crash somewhere later in your code? >>

nope. When I crash, I don't return from the function. Sometimes I crash running for the first time after a fresh boot up. Sometimes after loading and quiting after a few trys. Sometimes not at all. I can tell after the first time the function is called, afer a fresh boot up, it takes a second or so till it returns.

<< Always call DescribePixelFormat with the id you got and check if the pixelformat really contains the required features. >>

So what your saying is do this?...

pixelFormat = ChoosePixelFormat( hScreenDC, &pfd );
DescribePixelFormat( hScreenDC, pixelFormat,
sizeof(PIXELFORMATDESCRIPTOR), &pfd );
SetPixelFormat( hScreenDC, pixelFormat, &pfd ).

Is there an alternative way to do the above to avoid these odd problems?

Deiussum
01-12-2004, 01:48 PM
ChoosePixelFormat does not fill out the rest of the PIXELFORMATDESCRIPTOR for you, it just tries to find a pixelformat that closest matches what you requested. So, you should always use DescribePixelFormat to fill out the rest of the PIXELFORMATDESCRIPTOR before giving it to ChoosePixelFormat.

An alternative to ChoosePixelFormat, is to iterate through all the pixelformats by using DescribePixelFormat first with a pixelformat of 1, then 2, 3, 4, etc, until it returns 0, or you find a PIXELFORMATDESCRIPTOR with all the properties you want.

Edit: PIXELFORMATDESTRUCTOR? What was I thinking?!? Guess I still had my mind on some destructor code I just wrote for work.

[This message has been edited by Deiussum (edited 01-12-2004).]