Jump to content

  • Log In with Google      Sign In   
  • Create Account


wglMakeCurrent fails


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
11 replies to this topic

#1 ecco_the_dolphin   Members   -  Reputation: 122

Like
0Likes
Like

Posted 04 December 2009 - 06:07 AM

The problem is that sometimes (very-very-very rare) wglMakeCurrent(...) fails. GetLastError returns 2004 (ERROR_TRANSFORM_NOT_SUPPORTED - I dont know what this means). In the case if wglMakeCurrent fails during frame render pass, I just do nothing. The funny thing is that during next frame wglMakeCurrent succeeds and application runs fine. Could someone explain to me what the hell is going on? By the way, i use NVIDIA drivers 190.62; operating system is Windows XP.

Sponsor:

#2 empirical2   Members   -  Reputation: 561

Like
0Likes
Like

Posted 04 December 2009 - 08:34 AM

Interesting. I only call it once at start-up/on change display size.

Do you actually need to call it every frame?

#3 ecco_the_dolphin   Members   -  Reputation: 122

Like
0Likes
Like

Posted 04 December 2009 - 10:01 AM

Yes, I call it every frame. I do this because there are several windows in my app, and I use one OpenGL context for all of them, so I need wglMakeCurrent(...) for every window I want to draw in.

#4 Erik Rufelt   Crossbones+   -  Reputation: 3435

Like
0Likes
Like

Posted 04 December 2009 - 10:35 AM

Is the application single-threaded?
(Update to the latest drivers too, from nvidia.com, they are at 195.x now. Shouldn't matter ofcourse but you never know, always test on latest drivers, bugs get fixed all the time).

#5 ecco_the_dolphin   Members   -  Reputation: 122

Like
0Likes
Like

Posted 04 December 2009 - 10:42 AM

No, application is actually multithreaded (actually it is multithreaded ActiveX component). I use two OpenGL contexts: first is used for drawing into windows and second context is used by the second thread for rendering to texture (using FBO, by the way, I render not to an active texture. I mean that I actually have 2 textures, one is used by the first context and another by the second) which is used by the first context.

[Edited by - ecco_the_dolphin on December 4, 2009 5:42:26 PM]

#6 Erik Rufelt   Crossbones+   -  Reputation: 3435

Like
0Likes
Like

Posted 04 December 2009 - 12:13 PM

Sounds strange.. just a few ideas to check out:
Have you properly set the contexts up for sharing, through wglShareLists?
Is everything synced properly, so that you only try to use a context on one thread at once?
Read the remarks in the documentation for wglMakeCurrent.
Do you always use the same HDC to set the contexts?
I don't see what that error message means.. it says The requested transformation operation is not supported... but that doesn't really make much sense. Perhaps setting a matrix that isn't invertible or something? (If that is the type of transformation it's referring to at all). Or perhaps that error just happens to be the last one set because of a previous failure.

#7 ecco_the_dolphin   Members   -  Reputation: 122

Like
0Likes
Like

Posted 05 December 2009 - 12:13 AM

Quote:
Original post by Erik Rufelt
Do you always use the same HDC to set the contexts?
I don't see what that error message means.. it says The requested transformation operation is not supported... but that doesn't really make much sense. Perhaps setting a matrix that isn't invertible or something? (If that is the type of transformation it's referring to at all). Or perhaps that error just happens to be the last one set because of a previous failure.


Everything is synced properly, but I dont use the same HDC to set contexts, however I use HDCs with the equal pixel formats. Moreover in Debug build i have glGetError() call after almost every OpenGL function, so everything seems fine. I dont understand how wglMakeCurrent can fail and can succeed during next frame. I mean, application can run for a week, then for one frame wglMakeCurrent fails, and then application runs as usual. I use first context ONLY by the primary thread and second context ONLY by the second thread (except of initialization procedure). I dont render to an active texture, I synchronize texture names via SendMessageCall.

#8 ecco_the_dolphin   Members   -  Reputation: 122

Like
0Likes
Like

Posted 05 December 2009 - 12:35 AM

And before doing SendMessage to change texture names, i call glFinish() and wglMakeCurrent(0,0) by the second thread and also detach texture from FBO. Moreover whem I draw frame by the primary thread I call glBindTexture(GL_TEXUTRE_2D,0) at the end of a frame to make shure that texture is not current for the primary thread.

#9 Erik Rufelt   Crossbones+   -  Reputation: 3435

Like
0Likes
Like

Posted 05 December 2009 - 02:01 AM

Does it fail only on the primary thread, only on the texture rendering thread, or on both?
Can you solve it for example by a while(failed) { Sleep(10); wglMakeCurrent(...); }?
I'm mostly guessing, and I don't know how your application or ActiveX works behind the scenes, but perhaps for some reason something is changing in the background at regular (or irregular) intervals, like DC changes or something. If you call wglMakeCurrent at exactly a time in the duration of such a change, perhaps it is not able to set a current context right then.

#10 ecco_the_dolphin   Members   -  Reputation: 122

Like
0Likes
Like

Posted 05 December 2009 - 02:36 AM

Quote:
Original post by Erik Rufelt
Does it fail only on the primary thread, only on the texture rendering thread, or on both?


It happens only on primary thread, e.g on thread that renders to ActiveX controls. I have found the following words in remarks section at wglMakeCurrent. : "GDI transformation and clipping in hdc are not supported by the rendering context." Could these be related to ERROR_TRANSFORM_NOT_SUPPORTED code? If that so, then your quess could be true. Thanks for you reply, may be I should ask microsoft about this code...However, i get my HDC only once during window creation, I set pixel format and dont release this HDC untill window is destroyed. Is it true, that if application will get ANOTHER HDC of my window, and change its settings, these changes will affect my own HDC?

Quote:
Original post by Erik Rufelt
Can you solve it for example by a while(failed) { Sleep(10); wglMakeCurrent(...); }?


I will try that, but if your quess is true, it will not help, because if application behind the scenes changes my hdc settings and than changes it back, then it happens in application message loop. During Sleep aplication does not respond to window messages.

[Edited by - ecco_the_dolphin on December 5, 2009 9:36:56 AM]

#11 leonard2012   Members   -  Reputation: 167

Like
0Likes
Like

Posted 20 June 2012 - 10:23 AM

Hi ecco_the_dolphin,
How did you solve the wglMakeCurrent fail issure in the end? I've experienced the same problem.

#12 gravitino   Members   -  Reputation: 110

Like
1Likes
Like

Posted 25 July 2013 - 04:00 AM

I'd like to share a possible solution.

 

In my heavily concurrent application, I had the similar problems, though I had two possible error codes: ERROR_TRANSFORM_NOT_SUPPORTED or ERROR_INVALID_HANDLE, both appearing in an apparent in-deterministic manner, indicating a multithreading issue. I figured out that wglMakeCurrent ist *not* reentrant (at least when called on the same device context HDC, i didn't test the scenario when both, HDC and HGLRC, point to a different handle). By creating a spin-lock around wglMakeCurrent the problem disappeared for me.


Edited by gravitino, 25 July 2013 - 04:01 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS