PDA

View Full Version : OpenGL in multi threaded application



Tali Zvi
04-03-2001, 09:33 AM
Hi,

We have a multi-threaded plugin that runs under windows. Among other things, the plugin is a 3D viewer implemented with OpenGL. Whenever we refresh the browser (pressing F5), we destroy the existing window and create a new window, running in the same process. We have noticed that we have about 1-3M of memory leak every time we create a new OpenGL window.

Here are some points and observations:

1. The OpenGL calls are not executed in the main window thread. They are executed in a separate thread, that includes the wglCreateContext and wglDeleteContext as well, but does not contain the GetDC() and ReleaseDC calls.
2. The memory leak does not occur when hardware acceleration is disabled.
3. Approximately the same memory leak occurs with several graphics cards we have tried.
4. The amount of memory that is leaking appears to be proportional to the size of the window.
5. We have implemented a simple single-threaded OGL application, and the problem does not occur there.

The only conclusion we currently have, but we cannot confirm, is that OpenGL calls have to be executed from the main window's thread.
We are running this on Win2K, but we have observed memory leaks on Win98 as well.

Anyone knows anything about this?

Thanks, Tali

davepermen
04-03-2001, 10:24 AM
wich driver do you use? i have tried much much much drivers, and only 6.5 dont have memory leaks at all here! you dont need to create some multithread, no, try just running any program and take a look if you loose mem..

Tali Zvi
04-03-2001, 10:22 PM
If I do not use multithreaded application, I can not observe any memory leaks. My guess is that the fact that it is a multithreaded application causes the leak. It looks as if OpenGL does not release all the resources when the window is closed. wglDeleteContext is supposed to be responsible for that.

I am using the nVidia RIVA TNT2 chip with the newest version of the detonator (11.01). The problem was observed on any other chip/driver we have tried this on, so I don't think it is related to the card/driver.

paddy
04-03-2001, 10:45 PM
I noticed you manage the DC in the main thread and the context in the rendering thread.
Are you sure you first delete the context and then release the dc when closing the window ?

Should be (even in in separate threads) :

wglMakeCurrent(rd->data->dc, NULL);
wglDeleteContext(rd->data->hGLRC);
ReleaseDC(rd->data->hwnd,rd->data->dc);

Then eventually
DestroyWindow(rd->data->hwnd);

Tali Zvi
04-04-2001, 12:00 AM
Yes, we made sure things happen in this order exactly.

paddy
04-04-2001, 12:09 AM
I really can't see how to help further without seeing some source code :p