Qt OpenGL memory leak



  • Hello

    A have a strange behavior in my Qt OpenGL widget based application.
    I just define a widget (inherit from QGLWidget) and in the paintGL function draw large number of 2D lines (1000 x 1000 for test)
    A define a timer wich tick updageGL slot each 20 ms
    The memory takes 10mo each second until process reach 1Go and then memory usage drop to 20mo and restart growing, ...

    If, after painting my lines, I just put an instruction like glCallList () (which just draw 1 line), there is no more memory leaks (and all my previous lines are draw !!!)

    I have the same behavior with QT4.8.2 and VS 2008 and Qt5.0.1 with VS 2010.

    I dont understand why put a glCallList (or drawTExt for example) resolved the memory leak.

    My confiuration : Windows 7 64bits (compilation with x86) pro 8Go RAM Nvidia Quadro 1000M


  • Lifetime Qt Champion

    Hi,

    A look at your code would help us help you



  • Here is the paintGL function :

    @
    void MyGLWidget::paintGL ()
    {
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glColor3f (0.5,0.,0.);
    for (int i = -1000; i <= 1000; i += 1)
    {      
        glLineWidth(1.0);
        if (!(i))
        {
            glLineWidth(2.0);
        }
    
        glBegin    (GL_LINES);
        glVertex3i (i, -1000, -1);
        glVertex3i (i, 1000, -1);
        glEnd();
    
        glBegin    (GL_LINES);
        glVertex3i (-1000, i, -1);
        glVertex3i (1000, i, -1);
        glEnd();
    }
    
    glCallList (dummyLineId);
    

    }
    @

    With line glCallList (dummyLineId); no problem, without it, memory growing.


  • Lifetime Qt Champion

    That's indeed strange... The code looks fine to me.

    Since your vertices don't change, did you consider to use a vbo ? That would speed up things and you would only allocate the memory once.



  • In fact, all code is now in display lists, so no more problem :)
    But I want to understand why the memory increase with this simple drawing.
    A can have this problem in another situation so if i can understand with preformances are so strange it will be helpfull


  • Lifetime Qt Champion

    Only triangles are simple !

    More seriously, there can be several things that can interfere, the underlaying gl implementation, the nvidia drivers etc...

    Does it also happen when you tick updateGL at a slower pace ?



  • Yes, it always happen !
    Purhaps OpenGL implementation in Qt (if a try to do the same thing in glut api for example,no problem).


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.