Jump to content
  • Advertisement
Sign in to follow this  
scottrick49

help with memory leak

This topic is 3734 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, I am trying to track down a memory leak, and I am not sure what the problem is. I have tracked down the problem to a simplified version of my render function, but I do not know why it is leaking memory. Simply clearing the color and depth buffers and then swapping them is leaking memory.
void Render()
{
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
        glutSwapBuffers();
}
Also, here is the line I use to initialize the display.
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
Any suggestions?

Share this post


Link to post
Share on other sites
Advertisement
I remember old nVidia drivers having a GL memory leak when swapping buffers. See if it occurs without double-buffering.

Share this post


Link to post
Share on other sites
The code you have posted there does not have a memory leak, at least not one that anyone will be able to diagnose without access to your machine. GLUT is widely enough used (and old enough) that a widespread memory leak in such an essential function would quickly be found using google.

Can you post the full source (in [ source ] tags) to the smallest, complete program that demonstrates the problem? Also your video card and OpenGL driver version would be helpful.

Share this post


Link to post
Share on other sites
Here -

#include <iostream>
#include <GL/glut.h>
using namespace std;

void Display();
void LoopFunction();
void Render();

unsigned int i = 0;

void Display()
{

}

void InitializeGlut(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowPosition(100, 100);
glutInitWindowSize(400, 400);
glutCreateWindow("hatfat");

glutDisplayFunc(Display);
glutIdleFunc(LoopFunction);
}

void LoopFunction()
{ //only printing so my computer doesn't lock up as bad
printf("%d\n", i);
i++;
Render();
}

int main(int argc, char **argv)
{
InitializeGlut(argc, argv);
glutMainLoop();
return 0;
}

void Render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
}

This example bogs down my computer, but if you watch the task manager the memory skyrockets.

Share this post


Link to post
Share on other sites
Also:

NVIDIA GeForce 8400M GS

Main Driver: nvd3dum.dll, nvwgf2um.dll
Version: 7.15.0011.5669
Date: 10/4/2007

I am using a Dell m1330 laptop, and as far as I know, this is the latest version of the video driver.

OpenGL Version 2.1.1 (as returned by glGetString(GL_VERSION)

Share this post


Link to post
Share on other sites
Try to remove this:

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowPosition(100, 100);
glutInitWindowSize(400, 400);
glutCreateWindow("hatfat");
glutDisplayFunc(Display);
glutIdleFunc(LoopFunction);

And write this:

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowPosition(100, 100);
glutInitWindowSize(400, 400);
glutCreateWindow("hatfat");
glutDisplayFunc(LoopFunction);
//glutIdleFunc(LoopFunction);

BTW, you have to do glclear and draw whatever in glutDisplayFunc.

Hope this helps you.

Share this post


Link to post
Share on other sites
Quote:
Original post by scottrick49
This example bogs down my computer, but if you watch the task manager the memory skyrockets.


How rapid the memory usage increase? Can you describe it more clearly?

Share this post


Link to post
Share on other sites
Thanks for the replies. I have modified it so that it uses glutPostRedisplay() instead of calling the render function itself. It still has a memory leak. Also, changing the idle function to be the display function is not something I want to do, since it changes how my program operates.

Here is what I was just testing:

#include <iostream>
#include <GL/glut.h>
using namespace std;

void Display();
void LoopFunction();

unsigned int i = 0;

void Display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
}

void InitializeGlut(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowPosition(100, 100);
glutInitWindowSize(400, 400);
glutCreateWindow("hatfat");

glutDisplayFunc(Display);
glutIdleFunc(LoopFunction);
}

void LoopFunction()
{ //only printing so my computer doesn't lock up as bad
printf("%d\n", i);
i++;
glutPostRedisplay();
}

int main(int argc, char **argv)
{
InitializeGlut(argc, argv);

const GLubyte *pVersion = glGetString(GL_VERSION);
printf("VERSION = %s\n", pVersion);
glutMainLoop();
return 0;
}

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!