开发者

access violation in wglMakeCurrent

Sometimes in my OpenGL application I get an access violation in the following API call:

wglMakeCurrent(NULL, NULL);

The application only has one single thread, and I've c开发者_运维知识库hecked that before that call, both the DC and HGLRC that are currently used are correct and valid.

There are three different windows with OpenGL content, and they're all redrawn on WM_PAINT messages and if a refresh is required due to user interaction (e.g., picking an object).

Also this access violation happens on different machines with different graphic cards, so I don't think it's a driver issue.

What could make this API call crash? What should I investigate in the app code to find out where/why this happens? I'm really lost here since I've checked everything I could think of already. I hope someone can give me hints/ideas on what more to check.


Is the purpose of this call to release the current thread's device context? That is the only time passing NULL for both parameters is valid. From the documentation:

"If hglrc is NULL, the function makes the calling thread's current rendering context no longer current, and releases the device context that is used by the rendering context. In this case, hdc is ignored."

Further to Tarydon's suggestion of adding a glFlush, it appears this would be redundant:

"Before switching to the new rendering context, OpenGL flushes any previous rendering context that was current to the calling thread."

Given the API actually crashes, and does not simply result in a failure, the only suggestion I can think of is that the thread on which you are calling wglMakeCurrent to release the HGLRC is not the same thread context used to associate the HGLRC with that device context. So the driver may be looking up the wrong thread-local storage for the call, thus causing the crash.

What happens if you add some logging to your code and print the current thread ID just before each call to wglMakeCurrent?

See:

  • wglMakeCurrent reference on MSDN


Turns out that an updated graphics driver fixed the issue. So it was a problem in the driver.


Try adding a glFlush call just before you do this. Perhaps the rendering pipeline has not yet been fully flushed to the GPU.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜