Discussion:
Hanging on wglMakeCurrent()
Colin Fahey
2002-09-29 19:13:17 UTC
Permalink
2002 September 29th
Sunday

I compiled an OpenGL program under Windows 2000 with
Visual Studio .NET, and then I tried to execute under
Windows 98...

Everything works, except the code hangs on the following
call:

wglMakeCurrent( hDC, hRC )

I'm stumped. The DC and RC handles look okay.

If I don't do full-screen mode, EVERYTHING works,
including the wglMakeCurrent(...) call.

Okay, I'd have to do some research to figure out
the exact difference between the full-screen start-up
code path and the windowed mode code path.

But I wonder if anyone might know of a reason
why wglMakeCurrent(...) would HANG. I can
wait for a long time, and it just doesn't make it
to the next instruction.

I'm sorry for not describing the code in more detail,
but I'm hoping someone will know right away that
either wglMakeCurrent(...) should NEVER block for
any significant amount of time, or there is something
that definitely will cause wglMakeCurrent(...) to
block indefinitely (like starving some Windows
message loop, or something crazy like that).

--- Colin
***@earthlink.net


-----
FAQ and OpenGL Resources at:
http://www.geocities.com/SiliconValley/Hills/9956/OpenGL
--
Author: Colin Fahey
INET: ***@earthlink.net

Fat City Network Services -- 858-538-5051 http://www.fatcity.com
San Diego, California -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ***@fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB OPENGL-GAMEDEV-L
(or the name of mailing list you want to be removed from). You may
also send the HELP command for other information (like subscribing).
Jon Watte
2002-09-29 21:08:25 UTC
Permalink
Sounds like a bug. Try breaking in with MSDEV and see what the call chain is
and in what module you're hung. Dollars to donuts you're hanging in
something
like WaitForSingleObject or WaitForMultipleObjects, though -- showing that
there is a locking bug somewhere, but not where it is :-(

Are you using multiple threads? The same context cannot be current in more
than one thread at the same time. MakeCurrent may block until the context
becomes available, if it's currently current in another thread.

Cheers,

/ h+
-----Original Message-----
Sent: Sunday, September 29, 2002 12:13 PM
To: Multiple recipients of list OPENGL-GAMEDEV-L
Subject: Hanging on wglMakeCurrent()
2002 September 29th
Sunday
I compiled an OpenGL program under Windows 2000 with
Visual Studio .NET, and then I tried to execute under
Windows 98...
Everything works, except the code hangs on the following
wglMakeCurrent( hDC, hRC )
I'm stumped. The DC and RC handles look okay.
If I don't do full-screen mode, EVERYTHING works,
including the wglMakeCurrent(...) call.
Okay, I'd have to do some research to figure out
the exact difference between the full-screen start-up
code path and the windowed mode code path.
But I wonder if anyone might know of a reason
why wglMakeCurrent(...) would HANG. I can
wait for a long time, and it just doesn't make it
to the next instruction.
I'm sorry for not describing the code in more detail,
but I'm hoping someone will know right away that
either wglMakeCurrent(...) should NEVER block for
any significant amount of time, or there is something
that definitely will cause wglMakeCurrent(...) to
block indefinitely (like starving some Windows
message loop, or something crazy like that).
--- Colin
-----
http://www.geocities.com/SiliconValley/Hills/9956/OpenGL
--
Author: Colin Fahey
Fat City Network Services -- 858-538-5051 http://www.fatcity.com
San Diego, California -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
the message BODY, include a line containing: UNSUB OPENGL-GAMEDEV-L
(or the name of mailing list you want to be removed from). You may
also send the HELP command for other information (like subscribing).
-----
FAQ and OpenGL Resources at:
http://www.geocities.com/SiliconValley/Hills/9956/OpenGL
--
Author: Jon Watte
INET: ***@mindcontrol.org

Fat City Network Services -- 858-538-5051 http://www.fatcity.com
San Diego, California -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ***@fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB OPENGL-GAMEDEV-L
(or the name of mailing list you want to be removed from). You may
also send the HELP command for other information (like subscribing).
Colin Fahey
2002-10-01 07:13:18 UTC
Permalink
2002 September 30th
Monday

I think I figured out why wglMakeCurrent()
was hanging under Windows 98, and I thought
I'd share my theory to provoke some feedback.

Here is the expected sequence of events in my
OpenGL application:

[1] The main thread creates a window.

[2] The main thread creates and starts a "render" thread.

[3] The main thread sets a flag and goes to sleep,
and periodically emerges from the sleep and
checks a status, and it will repeat the sleep
again and again until the status is valid.

[4] The render thread eventually checks the flag,
and then creates a Render Context (RC), and
then does wglMakeCurrent(), and SHOULD go on
to set a status (that the main thread is
checking and waiting for).

[5] The main thread SHOULD eventually notice that
the status is valid and can advance to the
main Windows message "pump".

And here's my theory about why this fails under
Windows 98:

Under Windows 98, wglMakeCurrent(...) is waiting
for the window (with associated DC and RC) to
process some messages!

Since I don't advance to my message "pump" code
until wglMakeCurrent(...) finishes, there's
a deadlock.

Well, I learned my lesson: If there's a window
handle involved in any way (even very indirectly,
such as a DC or RC), keep pumping those messages!

For some reason (perhaps sanity prevails at last),
Windows 2000 is not affected by this problem!

Typical OpenGL programs, even multi-threaded ones,
never run in to this problem because most people
call wglMakeCurrent() because their "WndProc(...)"
told them to -- or the main thread isn't waiting
for the rendering thread, and just jumps right in
to the message "pump".

Any comments on the relationship between the
Windows message "pump" and the wglMakeCurrent(...)
function under Windows 98 (and what may have changed
under Windows 2000)?

It would be nice to have confirmation or rejection
of my theory.

--- Colin
***@earthlink.net


-----
FAQ and OpenGL Resources at:
http://www.geocities.com/SiliconValley/Hills/9956/OpenGL
--
Author: Colin Fahey
INET: ***@earthlink.net

Fat City Network Services -- 858-538-5051 http://www.fatcity.com
San Diego, California -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ***@fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB OPENGL-GAMEDEV-L
(or the name of mailing list you want to be removed from). You may
also send the HELP command for other information (like subscribing).
Toby Jones
2002-10-01 19:58:25 UTC
Permalink
This smells of a win16 mutex issue. You only want to have one thread that
does GUI stuff under Windows, otherwise you can deadlock. The thread that
creates the window should be the thread that creates the hdc, hglrc, and
does the opengl calls. WinNT and its successors don't have to worry about
this. This might be why you only see the problem under Win9x.

Toby Jones
Software Engineer
Human Head Studios, Inc.

-----Original Message-----
Sent: Tuesday, October 01, 2002 2:13 AM
To: Multiple recipients of list OPENGL-GAMEDEV-L


2002 September 30th
Monday

I think I figured out why wglMakeCurrent()
was hanging under Windows 98, and I thought
I'd share my theory to provoke some feedback.

Here is the expected sequence of events in my
OpenGL application:

[1] The main thread creates a window.

[2] The main thread creates and starts a "render" thread.

[3] The main thread sets a flag and goes to sleep,
and periodically emerges from the sleep and
checks a status, and it will repeat the sleep
again and again until the status is valid.

[4] The render thread eventually checks the flag,
and then creates a Render Context (RC), and
then does wglMakeCurrent(), and SHOULD go on
to set a status (that the main thread is
checking and waiting for).

[5] The main thread SHOULD eventually notice that
the status is valid and can advance to the
main Windows message "pump".

And here's my theory about why this fails under
Windows 98:

Under Windows 98, wglMakeCurrent(...) is waiting
for the window (with associated DC and RC) to
process some messages!

Since I don't advance to my message "pump" code
until wglMakeCurrent(...) finishes, there's
a deadlock.

Well, I learned my lesson: If there's a window
handle involved in any way (even very indirectly,
such as a DC or RC), keep pumping those messages!

For some reason (perhaps sanity prevails at last),
Windows 2000 is not affected by this problem!

Typical OpenGL programs, even multi-threaded ones,
never run in to this problem because most people
call wglMakeCurrent() because their "WndProc(...)"
told them to -- or the main thread isn't waiting
for the rendering thread, and just jumps right in
to the message "pump".

Any comments on the relationship between the
Windows message "pump" and the wglMakeCurrent(...)
function under Windows 98 (and what may have changed
under Windows 2000)?

It would be nice to have confirmation or rejection
of my theory.

--- Colin
***@earthlink.net


-----
FAQ and OpenGL Resources at:
http://www.geocities.com/SiliconValley/Hills/9956/OpenGL
--
Author: Colin Fahey
INET: ***@earthlink.net

Fat City Network Services -- 858-538-5051 http://www.fatcity.com
San Diego, California -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ***@fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB OPENGL-GAMEDEV-L
(or the name of mailing list you want to be removed from). You may
also send the HELP command for other information (like subscribing).
-----
FAQ and OpenGL Resources at:
http://www.geocities.com/SiliconValley/Hills/9956/OpenGL
--
Author: Toby Jones
INET: ***@HumanHead.com

Fat City Network Services -- 858-538-5051 http://www.fatcity.com
San Diego, California -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ***@fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB OPENGL-GAMEDEV-L
(or the name of mailing list you want to be removed from). You may
also send the HELP command for other information (like subscribing).
Loading...