Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: window.display() Creates Memory Leak with VBOs  (Read 1537 times)

0 Members and 1 Guest are viewing this topic.

LucasShadow

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
window.display() Creates Memory Leak with VBOs
« on: October 21, 2012, 05:35:06 am »
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:

   
#include <windows.h>
#include <iostream>
#include <sstream>
#include <fstream>
#include <SFML/Graphics.hpp>
#include <glew.h>
#include <gl/gl.h>
#include <gl/glu.h>

using namespace std;

class Scene {
public:
    void resize( int w, int h ) {
        // OpenGL Reshape
        glViewport( 0, 0, w, h );
        glMatrixMode( GL_PROJECTION );
        glLoadIdentity();
        gluPerspective( 120.0, (GLdouble)w/(GLdouble)h, 0.5, 500.0 );
        glMatrixMode( GL_MODELVIEW );
    }
};
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");

    ///Each vertex is in order for what is needed
    GLfloat vertices[] = { .5, .5, .5,  -.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, 48, 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_QUADS, 0, 4);

        glDisableClientState(GL_VERTEX_ARRAY);

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

        window.display();
    }

    return 1;
}

 

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. Its not much with the little bit of data I have, increases about 2,000 KB per second for me using Windows Task Manager to track the applications memory consumption.
« Last Edit: October 21, 2012, 05:42:59 am by LucasShadow »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: window.display() Creates Memory Leak with VBOs
« Reply #1 on: October 21, 2012, 09:41:05 am »
It's a driver issue.

Search "leak" on the forum and task tracker for more details.
Laurent Gomila - SFML developer

 

anything