PDA

View Full Version : Does the wglMakeCurrent(NULL, NULL) release the DC?



strawnut
07-04-2014, 06:47 AM
Hi.
I don't know English, well. So please understand me even if statements are wrong. :D

I saw following statement from wglMakeCurrent func page on MSDN(http://msdn.microsoft.com/ko-KR/library/ie/dd374387.aspx).


hglrc
Handle to an OpenGL rendering context that the function sets as the calling thread's rendering context.
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.

So, I thought that wglMakeCurrent(NULL, NULL) calls ReleaseDC() inner code of it. Although it's not ReleaseDC(), Device Context will be released, I think.
However, almost sample codes on online call ReleaseDC() after wglMakeCurrent(NULL, NULL). Even NeHe's sample code is also, too.

What does that mean?

Jesse
07-04-2014, 11:53 AM
Hi.
I don't know English, well. So please understand me even if statements are wrong. :D

I saw following statement from wglMakeCurrent func page on MSDN(http://msdn.microsoft.com/ko-KR/library/ie/dd374387.aspx).



So, I thought that wglMakeCurrent(NULL, NULL) calls ReleaseDC() inner code of it. Although it's not ReleaseDC(), Device Context will be released, I think.
However, almost sample codes on online call ReleaseDC() after wglMakeCurrent(NULL, NULL). Even NeHe's sample code is also, too.

I think you are reading too much into the description. The webpage states that the rendering context "releases the device context that is used by the rendering context". In other words, the rendering context is no longer coupled to that particular device context. Of course, I think it may still be a good idea to run a test under the debugger to see whether you end up with a resource leak if you don't call ReleaseDC() before assuming that it's not necessary.

strawnut
07-06-2014, 08:51 PM
I think you are reading too much into the description. The webpage states that the rendering context "releases the device context that is used by the rendering context". In other words, the rendering context is no longer coupled to that particular device context. Of course, I think it may still be a good idea to run a test under the debugger to see whether you end up with a resource leak if you don't call ReleaseDC() before assuming that it's not necessary.

Thank you for your answer.
As your opinion, I want to run a test if it is memory leak or not. However, I don't know the test way. If you don't mind, can you tell me the way?
_CrtDumpMemoryLeaks(); function can't do it.

Jesse
07-09-2014, 10:37 AM
Thank you for your answer.
As your opinion, I want to run a test if it is memory leak or not. However, I don't know the test way. If you don't mind, can you tell me the way?
_CrtDumpMemoryLeaks(); function can't do it.

If you call ReleaseDC() and then try to use the invalid handle, the program will crash and the debugger will generally notify you that there was an invalid operation. Presumably if you are correct in your assumption, calling wglMakeCurrent(nullptr, nullptr) will result in similar program behavior.

strawnut
07-15-2014, 07:32 PM
If you call ReleaseDC() and then try to use the invalid handle, the program will crash and the debugger will generally notify you that there was an invalid operation. Presumably if you are correct in your assumption, calling wglMakeCurrent(nullptr, nullptr) will result in similar program behavior.

Oh, Thank you very much.
I tried to run a test, and resulted that my assumption is false. If it doesn't call ReleaseDC() after calling wglMakeCurrent(NULL, NULL), the DC handle is still valid. So, though wglMakeCurrent(NULL, NULL) will be called, I have to call ReleaseDC(). Thanks. :D