Jump to content
  • Advertisement
Sign in to follow this  
nraiyani

Disappearing Memory when rendering with OGL

This topic is 4528 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
glGenList is only called in PrepareScene before the loop...

Sure looks like that GetHDC to me too.

Share this post


Link to post
Share on other sites
Quote:
glListBase(grid);


Why do you call this?

Also, there is no need to call glFlush because SwapBuffers does it for you.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!