wglMakeCurrent failure

I have noticed that this function fails when I call it when it’s time to shutdown ie, when the app receives WM_DESTROY.

When I call wglMakeCurrent(NULL, NULL) it succeeds, but then trying to make it current again with my previous GL context fails.
So I wanted to see what the problem is.
I called GetLastError which gives some number.
Then I used FormatMessage (which usually works), but it doesn’t return anything. The lpMsgBuf parameter remains NULL!

This is on ATI. On NV, it’s working.

Err …

The WM_DESTROY message is sent when a window is being destroyed. It is sent to the window procedure of the window being destroyed after the window is removed from the screen.
IOW the device context is already gone.

The message is sent when the window is beeing destroyed, but the handles are still valid. Also, every code I’ve seen do their cleanup during WM_DESTROY.

Where so you do your cleanup?

While I’ve never had trouble shutting down the GL in this way on NVIDIA hardware, the wording in the MSDN might give one pause. What exactly is meant by “removed from the sceen?”

As far as I can determine, they simply mean that the window is hidden and deactivated, but a window in every other respect.

You might try the GL shutdown before the window destruction, in the odd chance that it’s an ATI bug.

Originally posted by V-man:
The message is sent when the window is beeing destroyed, but the handles are still valid. Also, every code I’ve seen do their cleanup during WM_DESTROY.
Dunno. I never felt the need for trying that out. It sounds pretty dangerous to me.
You could probably as well just exit(0), but that’s really not my idea of a clean shutdown.

Where so you do your cleanup?
Before calling DestroyWindow.
Or when receiving a WM_CLOSE message, because the default window proc will call DestroyWindow.

It had occured to me that doing it in WM_CLOSE is possible, but I think WM_DESTROY is fine. I’m trying to clarify MSDN’s statement.

Considering the fact that the Red Book, SDK’s provided by major vendors, thousands of tutorials and free code do this kind of thing or don’t delete GL resources at all, one has to wonder.

I’m trying to find out what is the "right thing to do"TM and what is "the correct behavior"TM

Why should one vendor’s driver report a failure when it works on another.

I’m interested in what other people think.
:slight_smile:

did u have a look at the source code for sdl/glut?
also perhaps the unreal source.