简体   繁体   中英

OpenGL VBO Memory Leak

I am having some issues with the memory with a very simple OpenGL application that I wrote to learn VBOs. The memory it uses readily increases the longer it is open. Below is code the duplicates what I am seeing using Windows Task Manager:

int main() {

sf::RenderWindow window(sf::VideoMode(800, 600, 32), "Test");

///Setup the scene, materials, lighting
Scene scene;
scene.resize(800,600);

glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glColorMaterial(GL_FRONT_AND_BACK, GL_EMISSION);
glEnable(GL_COLOR_MATERIAL);
glShadeModel(GL_FLAT);
glEnable(GL_LIGHT0);
float XL = .5, YL = .1, ZL = 1;
GLfloat ambientLight[] = { 0.2f, 0.2f, 0.2f, 1.0f };
GLfloat diffuseLight[] = { 0.8f, 0.8f, 0.8, 1.0f };
GLfloat specularLight[] = { 0.5f, 0.5f, 0.5f, 1.0f };
GLfloat lightpos[] = {XL, YL, ZL, 0.};
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight);
glLightfv(GL_LIGHT0, GL_POSITION, lightpos);

glGenBuffersARB = (PFNGLGENBUFFERSARBPROC)wglGetProcAddress("glGenBuffersARB");
glBindBufferARB = (PFNGLBINDBUFFERARBPROC)wglGetProcAddress("glBindBufferARB");
glBufferDataARB = (PFNGLBUFFERDATAARBPROC)wglGetProcAddress("glBufferDataARB");
glBufferSubDataARB = (PFNGLBUFFERSUBDATAARBPROC)wglGetProcAddress("glBufferSubDataARB");
glDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC)wglGetProcAddress("glDeleteBuffersARB");
glGetBufferParameterivARB = (PFNGLGETBUFFERPARAMETERIVARBPROC)wglGetProcAddress("glGetBufferParameterivARB");
glMapBufferARB = (PFNGLMAPBUFFERARBPROC)wglGetProcAddress("glMapBufferARB");
glUnmapBufferARB = (PFNGLUNMAPBUFFERARBPROC)wglGetProcAddress("glUnmapBufferARB");

GLfloat vertices[] = { .5, .5, .5,  -.5, .5, .5,  -.5,-.5, .5};

GLuint VBOID;
glGenBuffersARB(1, &VBOID);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBOID);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, 108, vertices, GL_STATIC_DRAW_ARB);

///Start loop
cout << "Starting" << endl;
while( window.isOpen() ) {
    sf::Event event;
    while( window.pollEvent( event ) ) {
        if( event.type == sf::Event::Closed )
            window.close();
    }

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(50.0, 1.0, 1.0, 50);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(5, 5, 5, 0, 0, 0, 0, 1, 0);

    glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBOID);
    glEnableClientState(GL_VERTEX_ARRAY);

    glVertexPointer(3, GL_FLOAT, 0, 0);
    glDrawArrays(GL_TRIANGLES, 0, 3);

    glDisableClientState(GL_VERTEX_ARRAY); 

    ///Reset env settings for SFML
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    window.display();
}

return 1;

}

EDIT:

Commenting out all event polling changes nothing. The window clearing doesnt seem to make a difference if I use window.clear() or opengl's clear function.

With further commenting out I was able to figure out that the one line of code, window.display(), is causing my memory leak. Ill see if the guys at the SFML forums can figure this one out ;)

I can't see anything in your draw loop that should cause this behaviour.

I think you should try the SFML forum : http://en.sfml-dev.org/forums/

There are several threads about this issue :

The developers mostly claim that this is a driver issue. You could try to disable all your draw code and see if that changes anything. Use window.clear() instead? Remove the event polling?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM