Disappearing Memory when rendering with OGL

Started by
7 comments, last by Jaywalk 17 years, 11 months ago
Hi, Perhaps some of you can help me spot some error that i am making here Problem i am having is, that my rendering loop seems to be eating memory but i can't tell where. it seems to be taking up 20/30k every few frames. And that is irritating me to no end. Here is how my Rendering loop looks like

pEngine->PrepareScene();
while (1)
{
	if (PeekMessage(&uMsg, NULL, 0, 0, PM_REMOVE))
	{
		if (uMsg.message == WM_QUIT)
			break;
		TranslateMessage(&uMsg);
		DispatchMessage(&uMsg);
	}

	pEngine->Cycle();
}
pEngine->DeleteScene();

this PrepareScene looks like this

	glShadeModel(GL_SMOOTH);
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClearDepth(1.0f);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

	grid = glGenLists(1);
	glNewList(grid, GL_COMPILE);
		glBegin(GL_LINES);
			glColor3f(1.0f, 1.0f, 1.0f);
			for(int i=-100; i<101; i++)
			{
				glVertex3i(i, 0, -100);
				glVertex3i(i, 0, 100);
				glVertex3i(-100, 0, i);
				glVertex3i(100, 0, i);
			}
		glEnd();
	glEndList();

So its a pretty simple DisplayList, just a plain simple Grid. And the Cycle method has following

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
	glLoadIdentity();

	gluLookAt(0.0, 1.0, -5.0, 
			0.0, 0.0, 5.0, 
			0.0, 1.0, 0.0);

	glPushMatrix();
		glListBase(grid);
		glCallList(grid);
	glPopMatrix();

	glFlush();
	SwapBuffers(m_pWindow->GetHDC());

It seems to be eating memory during the Cycle function. But i can't figure out why. I read a few thread about wglMakeCurrent doing similar things, But that function isn't in my render loop. And i can't figure out what i am missing.
42
Advertisement
Hmm I would suggest that it's something to do with the GetHDC call at the end. If that function continually gets a new copy of the DC (e.g. like a call to GetDC without a call to ReleaseDC does) then that will leak memory. Check in Task Manager if your number of GDI objects keeps increasing during the running of your application, and if so, that might be it.
Also i see that you are calling glGenList every frame yet, you are not deleteting them afterward
glGenList is only called in PrepareScene before the loop...

Sure looks like that GetHDC to me too.
Quote:glListBase(grid);


Why do you call this?

Also, there is no need to call glFlush because SwapBuffers does it for you.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
glflush is just reflex thing. so ignore that part

I changed the code to that instead of calling the SwapBuffers Function from Cycle method

I am calling it from my Window Class object

void Swap(void){    SwapBuffers(m_hDC);}


however memory still keeps increasing. by 8 to 12kb per frame
the GDI Object count remains steady at 22
And i've noticed that Mem Usage eventually flattens out around 9900-10000kb.

But i am at a loss to understand why this is.


Also as i understand it, (could be a flaw in that, it has been known to happen)
glListBase() function sets the active Display List. and has to be set before glCallList() can be called.

42
Quote:Original post by nraiyani
Also as i understand it, (could be a flaw in that, it has been known to happen)
glListBase() function sets the active Display List. and has to be set before glCallList() can be called.


Actually, you use glListBase() to set the starting index of your display lists, and you can then use glCallLists() to call a set of lists using the indices you supply to glCallLists(). It's handy if you plan on rendering things like text, where you can just dump a lot of text into it, and use the characters as the indices. In any case, if you're only going to use one display list, you don't have to call glListBase().

[EDIT]
Before I forget, the whole memory not increasing thing can be attributed to the OS dumping things into your page file, rather than keeping it all in system memory.

By the way V-man, calling glFlush() should start rendering the scene after the call, rather than waiting for the buffers to be filled, or waiting for the buffers to be flipped. Essentially, calling it before doing something that requires a lot of CPU resources can get the rendering done while the computer's doing something else, which means you usually don't have to wait as long when finally flipping the buffers. At least that's the way I understand it...

[EDIT 2]
Removed the whole HDC thing, since I didn't quite finish reading all of nraiyani's last post. In any case, I can't see anything wrong with the code as it is.
you could try IBM's purify (comercial, but they have an evaluation version) or valgrind (if your app runs on linux) or memwatch (windows and unix)
There is a chance that the problem is in the window procedure, if it's not in Cycle(). It might be a good idea to take a look at the window procedure just in case.

This topic is closed to new replies.

Advertisement