Release OpenGL before window destruction

I have a process in place where opengl’s context is released before the window is destroyed. I have found however that on this new video card that this is producting errors during the shutdown

VS.NET Output Windows says:

WGL Message:WGL: __wglDDrawSurfaceRestore: IsLost: DDERROR = DDERR_SURFACELOST during game.exe shutdown.

I was casually reading some Mesa source code yesterday and noticed a comment about some cards hanging on the the D3D context until the window is destroyed. The code destroyed the window at that point rather than releasing the context.

Doesa nyone know anything about this kind of weird behaviour?

Don’t make any OpenGL calls or try to bind the context after you delete the window.

Sounds like you’re getting an expose event or something else is leading to the onDraw function (or whatever), and it is trying to use the context you’ve just deleted.

So, when you delete the window, make sure your draw code knows about it and even if invoked (maybe by some queued event) doesn’t try to use it.

You may also want to clear out the event buffer just before deleting it, up to you really.