memory leak in "glDeleteList"

Hello, I have created a opengl app which use “glCallList” function to draw polygons.

When the Window is going drawing the scene I create and compile a lot of glNewLists for draw faster polygonal elements.

A working thread verify if there elements can be deleted, It use “glDeleteLists” functions.

But, I see that the memory has not released it the proccess window. Why ???

CMapFile::setupPolygon()
{
if (ixNewList)
{
glCallList(ixNewList);
return;
}


ixNewList = (GLuint)pElement; // pElement == (pointer of a graphic element)
glNewList(ixNewList, GL_COMPILE_AND_EXECUTE);

// … draw/compile polygons.
GLUtesselator * p_objTesseler = gluNewTess();
if (!p_objTesseler) {if (ixNewList) glDeleteLists(ixNewList, 1); ixNewList = 0; return;}

gluTessCallback(p_objTesseler, GLU_TESS_BEGIN, (TessFuncPtrDef)glBegin);
gluTessCallback(p_objTesseler, GLU_TESS_VERTEX, (TessFuncPtrDef)glVertex3dv);
gluTessCallback(p_objTesseler, GLU_TESS_EDGE_FLAG, (TessFuncPtrDef)glEdgeFlag);
gluTessCallback(p_objTesseler, GLU_TESS_END, (TessFuncPtrDef)glEnd);

gluTessBeginPolygon(p_objTesseler, NULL);
gluTessBeginContour(p_objTesseler);
for (i = 0; i < pElement->NumPoints; i++) gluTessVertex(p_objTesseler, (GLdouble *)(pElement->pPoints+i), (GLdouble *)(pElement->pPoints+i));
gluTessEndContour(p_objTesseler);
gluTessEndPolygon(p_objTesseler);

gluDeleteTess(p_objTesseler);

glEndList();
}

and a thread verify Elements for clear memory …

CMapFile::clearPolygon()
{
if (ixNewList) {glDeleteLists(ixNewList, 1); ixNewList = 0;}
}

thank you very much

The first thing that comes to mind is to make sure you’re making the rendering context (in which the display lists were generated) current to the thread in which you are deleting them prior to trying to delete those lists.

The second thing is to make sure your cleanup thread is actually running. Depending on how you launched that cleanup function, it may simply spawn a new thread and exit very quickly without getting a chance to do any work.

And finally, make sure that creating a seperate thread for the cleanup task is the best solution. The way you’ve got it right now looks like asynchronous cleanup instead of an independent garbage collection thread - you’ll probably waste time on OS calls for thread init/shutdown if you’re just doing an async cleanup of your display list.

Enjoy,
– Jeff

Hi, I have seen my the problem.

I have a CWnd which create cleanup threads whith the “AfxBeginThreah” MFC function.

When the WM_PAINT routine of this CWnd is working, it has the HGLRC “locked” with “wglMakeCurrent” in order to draw shapes.

Then, if the task manager swap the CPU to an cleanup thread, all “OpenGL” functions fail, (“glDeleleLists”, …), because “wglGetCurrentDC” and “wglGetCurrentContext” return NULL.

… and “wglMakeCurrent” also returns 0 while I don’t “unlock” the HGLRC ih the WM_PAINT routine.

I supose that it must synchronize the HRC use of…

wglMakeCurrent(HDC, HGLRC);
wglMakeCurrent(NULL, NULL);

uf, sorry my english!
thanks your reply.