Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: wglMakeCurrent fails  (Read 5682 times)

0 Members and 1 Guest are viewing this topic.

slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
wglMakeCurrent fails
« on: September 05, 2013, 01:04:53 pm »
Sometimes, on various hardware platform we use, wglMakeCurrent fails and GetLastError returns 170 ("The requested resource is in use."). A quick hack to retry 100 times also fails.

I have 2, sometimes 3 windows, but our program is single threaded. Does anyone have any ideas why this might happen, and how I can check for what has control of this context?

Our program has 9 OpenGL contexts (that is, I can see 9 calls to createContext) which might be too many for this crappy hardware :(

Thanks
SFML 2.1

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: wglMakeCurrent fails
« Reply #1 on: September 05, 2013, 01:41:37 pm »
I have no idea, sorry. This is the first time I ever hear about this error :-\

Maybe OpenGL debuggers/tracers could help?

Do you use custom OpenGL calls? Multiple threads dealing with contexts?

Quote
Our program has 9 OpenGL contexts (that is, I can see 9 calls to createContext) which might be too many for this crappy hardware
SFML creates hidden contexts, but most of them are not active and are there only for resource sharing.
Laurent Gomila - SFML developer

slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
Re: wglMakeCurrent fails
« Reply #2 on: September 05, 2013, 05:20:47 pm »
Using a tracing program, I found the following when the problem occurs:

glViewport(0,0,1920,1081)
glMatrixMode(GL_MODELVIEW)
glPopMatrix()
glMatrixMode(GL_PROJECTION)
glPopMatrix()
glMatrixMode(GL_TEXTURE)
glPopMatrix()
glMatrixMode(GL_MODELVIEW)
wglSwapBuffers(42010BE0)=true
glEnable(GL_TEXTURE_2D)
wglMakeCurrent(A5010C00,00010003)=false                            <------------------ This is the problem
wglMakeCurrent(A5010C00,00010003)=false
(repeated another ~10 times)

So basically it's failing here - which is the 2nd window I have open. Very strange.
« Last Edit: September 05, 2013, 05:22:38 pm by slotdev »
SFML 2.1

slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
Re: wglMakeCurrent fails
« Reply #3 on: September 06, 2013, 03:43:58 pm »
I'm trying certain things to try and fix this. Is there a way to force use of a specific version of OpenGL?
SFML 2.1

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: wglMakeCurrent fails
« Reply #4 on: September 06, 2013, 06:15:29 pm »
Quote
Is there a way to force use of a specific version of OpenGL?
See the sf::ContextSettings that you pass at window creation.
Laurent Gomila - SFML developer

slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
Re: wglMakeCurrent fails
« Reply #5 on: September 20, 2013, 11:01:25 am »
Been doing some work on this problem. I can see there is more than 1 thread which is calling wglMakeCurrent, from a log file:

wglMakeCurrent call, thread ID 3812
wglMakeCurrent call, thread ID 2880
wglMakeCurrent call, thread ID 3812

So, in a single threaded application, what can be creating another thread? I know for sure that our code doesn't create any. Strange.
SFML 2.1

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: wglMakeCurrent fails
« Reply #6 on: September 20, 2013, 11:03:51 am »
SFML doesn't create extra graphics threads.

Where do you put your log call? Did you install some kind of global hook on the wglMakeCurrent function?
Laurent Gomila - SFML developer

slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
Re: wglMakeCurrent fails
« Reply #7 on: September 20, 2013, 12:32:46 pm »
I just added:

DWORD dwThread = GetCurrentThreadId();
err() << "wglMakeCurrent call, thread ID " << dwThread << std::endl;
 

to WglContext::makeCurrent. The only hook is to SetWindowPos function.

Also, it seems that our application has 11 threads running. I assume audio could be responsible for some of these threads....
SFML 2.1

slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
Re: wglMakeCurrent fails
« Reply #8 on: September 20, 2013, 01:09:00 pm »
Just looking at what threads are running, and of my 11 threads, 8 are audio (OK), 1 is window (OK), 1 is main thread (duh!) and 1 is caused by this line of code

gfxEngine = new GfxEngine();

..which calls the constructor of this class, and I guess since SFML gets initialised here, this is why it makes another thread?
SFML 2.1

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: wglMakeCurrent fails
« Reply #9 on: September 20, 2013, 01:49:34 pm »
There's no global SFML initialization, and there's no thread launched by SFML other than in the audio module.
Laurent Gomila - SFML developer

slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
Re: wglMakeCurrent fails
« Reply #10 on: September 20, 2013, 04:15:46 pm »
There is something strange going on where another thread is created by something Windows does when this class is instatitated.

But, I found the problem - I was doing a display(); call from a callback function which is triggered by an external process  :-[

Hope I didn't waste anyone's time..
SFML 2.1

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: wglMakeCurrent fails
« Reply #11 on: September 20, 2013, 04:18:59 pm »
No problem, I'm glad you solved it :P
Laurent Gomila - SFML developer

 

anything