I was recently working on implementing an OpenGL layer to our rendering engine and was using GLIntercept to find out what was going on “under the bonnet”. The first problem I encountered was that some of my asserts for GL_NO_ERROR == glGetError() were firing, in seemingly benign locations. After a whole lot of Google detective work, I found what I believe to be the conclusive diagnosis for this issue. It seems to be an artefact of a particular setup combination – NVidia drivers (I have a GeForce 8400M GT in a Dell Vostro laptop) and Vista.
The post below describes how the NVidia driver is unusual in that it fires off another thread which calls wglGetPixelFormat whenever SwapBuffers is called, and if you are running GLIntercept, this multithreaded access causes a false positive to occur. I think the reason my asserts were firing is that the gl error state persisted beyond the SwapBuffers and fired whenever the next gl command was issued.
Anyway, I hope this find is of use to someone, it’s taken me a couple of days to work it out!
I found my rendering problem and have posted another message requesting help with that (dirtying color arrays when vbo are used). I also tracked down the problem in GLIntercept. I have hacked up a fix for that but a proper one will require a far more comprehensive look at the architecture of GLIntercept.
The problem stems from the fact that the underlying driver is making calls back into OpenGL on another thread when some OpenGL functions are called. and that GLIntercept intercepts calls to glGetError and returns a cached error value in some circumstances.
This leads to the following.
1. Main thread calls SwapBuffers (windows GDI function) which eventually calls wglSwapBuffers which is intercepted by GLIntercept.
2. GLIntercept end up calling the real glGetError to check the result of the wglSwapBuffers.
3. The nvidia drivers implementation of glGetError for some reason tells (or maybe creates) another thread to do some work and waits for it to complete.
4. The other thread calls wglGetPixelFormat which is intercepted by GLIntercept, which again calls the real glGetError, luckily this does not seem to bother with another OpenGL call, however the cached error code is now messed up.
5. The worker thread releases the main thread which returns
6. The main thread calls glGetError (I have the OSG check every frame option set) and gets a bad cached value from GLIntercept.My fix is very hacky and just stops GLintercept calling glGetError if it is already in the process of doing so. This gets rid of most of the spurious errors.
I dont plan to go much further. GLIntercept also crashes on program exit it the runtime heap checks. But the logs seem OK. Let moe know if you want the modified code.
The problem stems from the fact that the underlying driver is making calls back into OpenGL on another thread when some OpenGL functions are called. and that GLIntercept intercepts calls to glGetError and returns a cached error value in some circumstances.
This leads to the following.
1. Main thread calls SwapBuffers (windows GDI function) which eventually calls wglSwapBuffers which is intercepted by GLIntercept.
2. GLIntercept end up calling the real glGetError to check the result of the wglSwapBuffers.
3. The nvidia drivers implementation of glGetError for some reason tells (or maybe creates) another thread to do some work and waits for it to complete.
4. The other thread calls wglGetPixelFormat which is intercepted by GLIntercept, which again calls the real glGetError, luckily this does not seem to bother with another OpenGL call, however the cached error code is now messed up.
5. The worker thread releases the main thread which returns
6. The main thread calls glGetError (I have the OSG check every frame option set) and gets a bad cached value from GLIntercept.
My fix is very hacky and just stops GLintercept calling glGetError if it is already in the process of doing so. This gets rid of most of the spurious errors.
I dont plan to go much further. GLIntercept also crashes on program exit it the runtime heap checks. But the logs seem OK. Let moe know if you want the modified code.
My latest toy is
Brian Auer offered an