Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Does the wglMakeCurrent(NULL, NULL) release the DC?

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2013
    Location
    South Korea
    Posts
    5

    Post Does the wglMakeCurrent(NULL, NULL) release the DC?

    Hi.
    I don't know English, well. So please understand me even if statements are wrong.

    I saw following statement from wglMakeCurrent func page on MSDN(http://msdn.microsoft.com/ko-KR/libr.../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?

  2. #2
    Junior Member Newbie
    Join Date
    Jul 2011
    Location
    USA
    Posts
    23
    Quote Originally Posted by strawnut View Post
    Hi.
    I don't know English, well. So please understand me even if statements are wrong.

    I saw following statement from wglMakeCurrent func page on MSDN(http://msdn.microsoft.com/ko-KR/libr.../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.

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2013
    Location
    South Korea
    Posts
    5
    Quote Originally Posted by Jesse View Post
    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.

  4. #4
    Junior Member Newbie
    Join Date
    Jul 2011
    Location
    USA
    Posts
    23
    Quote Originally Posted by strawnut View Post
    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.

  5. #5
    Junior Member Newbie
    Join Date
    Feb 2013
    Location
    South Korea
    Posts
    5
    Quote Originally Posted by Jesse View Post
    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •