Question

I started creating a small game engine for an independent project. When writing the graphics portion of the engine, I noticed there was a memory leak that dissapears when I stop using glClearColor and the glPushMatrix/glPopMatrix pairs. From what I've researched it appears to be a common occurrence, but I haven't found an answer as to why this occurs.

The bizarre thing is, the leak goes on for a minute or two, and then just stops (very consistently). Using the task manager, it shows 11,012K when the leak stops.

Additional Notes: I am not using GLUT, but I am using GLEW_1.7 for mapped vbo's.

Any ideas what could be causing this? Is is just a non-issue because of something odd that OpenGL does under the hood?

These are the only place I'm calling glClearColor, glPushMatrix, and glPopMatrix.

void GraphicsDevice::updateCameraAndClear(IWindow* window)
{
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(32, window->getAspectRatio(), 0.0, 100.0);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glClearColor(100.0f / 255, 149.0f / 255, 237.0f / 255, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glEnable(GL_CULL_FACE); // Enable Culling
    glCullFace(GL_BACK);
    glEnable(GL_NORMALIZE);
    glEnable(GL_POLYGON_SMOOTH);
}

void Engine::draw(void)
{
    GraphicsDevice::Instance()->updateCameraAndClear(_window);
    if ( !_states.empty() )
    {
        for(std::vector<IState*>::iterator i = _states.begin(); i != _states.end(); i++)
        {
            glPushMatrix();
            (*i)->draw(this);
            glPopMatrix();
        }
    }
}
Was it helpful?

Solution

Perhaps you use the Push/Pop pair wrongly, pushing one extra time more than required. But eventually that would lead to buffer overflow..

Check your Push/Pop pairs and make sure thay are pairs indeed. The leak could be in surrounding code as well.

EDIT: OpenGL receives instructions, but they are not executed immediately. OpenGL has a plan of its own. If you glDeleteTextures you are not guaranteed the texture will be removed until glFinish/glFlush command (or even after?). Maybe there's something else accumulating in your Draw code that OpenGL keeps in memory. Which gives described effect when co-joined with glPush/glPop pairs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top