View Full Version : wglMakeCurrent returning ERROR_BUSY #2

01-17-2012, 09:05 AM
I have same problem as in this topic(http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=196208&page=2)

I have different theads and each thread has different OpenGL context (each context has different Window (and DC)). These threads work simultaneously.

Each thread makes:
1. Set current context.
2. Make OpenGL operation.
3. Set current context NULL.
4. Any CPU work.
5. Set current context.
6. and so on.

Sometime very rarely I have ERROR_BUSY after wglMakeCurrent (I use getLastError).

I work under Windows.

01-17-2012, 10:06 AM
If you've got separate contexts for each thread, you do not need to make them current on each draw call. Just once, at startup.
What you get is quite a normal behavior.

01-17-2012, 10:11 AM
I must make SetCurrentContext for each rendering, because my component is used in big software system.

01-17-2012, 10:27 AM
Then make your method to access rendering context that tries to get it untill succeedes. In other words, make a wrapper around MakeCurrent. That's what I did long time ago to make it work properly with multithread access.

01-17-2012, 10:36 AM

I tried this method. But if I tried MakeCurrent second time, it returned ok, but next call of MakeCurrent for this thread return ERROR_BUSY. It makes my component very slow.

I hope there is normal method for fix this problem.

01-17-2012, 01:28 PM
I hope there is normal method for fix this problem.

A "normal" method would be using critical sections (or similar synchronization mechanism) to protect access to each context, or implementing all drawing in threads that own contexts and develop a mechanism to send them messages telling them what to draw.

01-18-2012, 02:35 AM
Yes, critical sections are my current solution!

But I want to make multi-threaded render, I think it can be faster.

May be somebody knows the reason why this error occurs.