Corrupt opengl context

Hello everyone,

searching for a bug, I came across some strange behavior of my app. Actually this behavior shows shortly before exiting (in some destructur in a class wrapping occulsion culling). I assume, that the opengl context is already destroyed BUT how do I know for sure.

Basically I am doing the following to check if there is a context:

if(wglGetCurrentContext()) {

if(glIsQuery(m_queryID)) {
glDeleteQueries(1, &m_query);


The programs crashes when calling glIsQuery (which is called several times during lifetime of the application, therefor there is no problem with taht extension so something like that).

I tried the following code for debugging purposes and it became even stranger:

if(wglGetCurrentContext()) {
char* version = (char*)glGetString(GL_VERSION);
GLenum error = glGetError();

// version is NULL now and error as well 0

So is there anyway, that wglGetCurrentContext returns a non-invalid handle but the context is not really valid anymore?

Did somebody had similar problems?

Thanks and regards,

Try wglMakeCurrent to determine if RC and DC are still valid.


Thanks Shinta. Reasonable idea. I tried this:

1       bool foundContext = false;
2       HGLRC rc = wglGetCurrentContext();
3       HDC   dc = wglGetCurrentDC();
4       if(rc != NULL && dc != NULL) {
5           foundContext = wglMakeCurrent(dc, rc);
6           if(!foundContext) {
7               DWORD error = GetLastError();
8           }
9       }

The result: an app crash (The program ‘…’ has exited with code 0 (0x0).) in line 5 - when trying to call wglMakeCurrent. No memory error nor something else promted by the debugger.

Any idea?

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.