wglMakeCurrent - strange error

I have a strange error with wglMakeCurrent.

In my application there are multiple threads which are rendering to one single context. The draw Operations are secured by a Semaphore, so the threads should not interfere with each other.

Each thread basically looks like this


Draw(); // this is where all drawing is done


Now, whenever i call wglMakeCurrent(NULL,NULL); i get an OpenGL error GL_INVALID_OPERATION.

The strange thing is that everything is rendered exactly as it should be and wglMakeCurrents always returns TRUE … so i would expect that there was no error. OpenGL seems to think different.

Does anyone have an idea what the problem could be?

For one thing you need to make sure you release your context in the current thread (which I believe will flush the command buffer - see the MSDN on Windows); otherwise you’ll likely get an invalid handle error on e.g. SwapBuffers (check GetLastError on Windows).