wglDeleteContext causing problems

I’ve traced the source of an error message to my call to wglDeleteContext(). Anyone know what sort of thing would cause this call to fail to disastrously?

I’m running Win2k (havn’t had a chance to try it on anything else yet), and the exact error message (when compiled in debug mode) is:
Unhandled exception in <app name> (NTDLL.DLL): 0xC0000005: Access Violation.

The order of my calls is:


Any ideas?

If it returned false, you can call GetLastError right afterwards to see what the error was.

If the context has been made current in a different thread, this function will fail.

Actually, it’s not returning false because it’s not returning anything. It causes the program to crash when it is called. It does not have a chance to return anything.

I am recording an answer to this here for posterity. I had the same issue (crash when calling wglDeleteContext, but only when using a texture) eventually found that the error was holding on to GL objects (textures, buffers etc) at the point wglDeleteContext() was called. When I updated my code to free the textures, delete buffers & VAOs prior to calling wglDeleteContext (), I got a clean run.

So I believe this is a case of OpenGL implementations, or the microsoft library that wraps them, complaining about deleting a context with active objects in it. Cleaning everytjing up solves the problem.