PDA

View Full Version : Calling wglMakeCurrent cause memory leak ?



Mikazz
10-09-2011, 11:20 PM
I recently found a memory leak in my project, and when I tried to comments the wglMakeCurrent calls I found that the memory leak was gone.

I'm currently wondering if I'm using it right. I'm using a thread pool with multiple tasks to execute and one of this task o render a scene with openGL. Since I never know which threads is going to execute this task I'm calling wglMakeCurrent(DC, RC) each frames just before using openGL, and I'm calling wglMakeCurrent(NULL,NULL) at the end of the frame. Which means that the openGL context is set and unset around 60 times by second.

However, there is a memory leaks. Is it a bug, or maybe I should not call wglMakeCurrent each frames and bind this task exclusively to the main thread ?

I found that only using wglMakeCurrent(DC, RC) without calling wglMakeCurrent(NULL,NULL) or calling wglMakeCurrent(NULL,NULL) without using wglMakeCurrent(DC, RC) doesn't cause a memory leak.

My graphic device is a NVidia 285 GTX

Aleksandar
10-10-2011, 11:38 AM
However, there is a memory leaks. Is it a bug, or maybe I should not call wglMakeCurrent each frames and bind this task exclusively to the main thread ?
That must be a bug, but who is responsible for it we have to determine yet.


I found that only using wglMakeCurrent(DC, RC) without calling wglMakeCurrent(NULL,NULL) or calling wglMakeCurrent(NULL,NULL) without using wglMakeCurrent(DC, RC) doesn't cause a memory leak.
Without calling wglMakeCurrent(NULL,NULL), you cannot use that context from the other thread. Are you sure that wglMakeCurrent() creates a memory leak? If the context is not active no one GL call can succeed.


My graphic device is a NVidia 285 GTX
The particular graphics card is not important in this problem, but rather the driver. You also have to give more details about the implementation. Of course, a faster solution is to bind GL context just to a single thread and send commands from the others. wglMakeCurrent() calls certainly reduce the execution speed.

Mikazz
10-10-2011, 03:22 PM
I found the problem!

My memory leak was actually elsewhere. When I decided to remove all graphic draw calls I tried to keep calling wglMakeCurrent without calling SwapBuffers with SDL. However I found that calling wglMakeCurrent without calling the SDL SwapBuffers cause a memory leak and I tough it was THE memory leak.

Finally I fixed the memory leak in my code and it work perfectly. Thanks for your help =)