Memory Leak in Draw method with QPainter and QOpenGLPaintDevice



  • Hello,
    the memory usage of my draw method is growing in a exponential way :). I dont know where the Problem is. My class is inheriting from QWindow and QOpenGLFunctions. I am drawing out of the paint event. The draw method is called by a signal from a other thread, which implements a loop for updating and drawing(signal).
    @
    void Initialize() {
    loadAssets( "asset_list.xml" );

    // initialize graphics
    setScreen( m_screen );
    setSurfaceType( QSurface::OpenGLSurface );
    setWindowState( Qt::WindowFullScreen );

    resize( 1280, 720 );
    show();

    m_context = new QOpenGLContext( this );

    m_context->setFormat( requestedFormat() );
    m_context->create();
    m_context->makeCurrent( this );

    initializeOpenGLFunctions();

    m_paintDevice = new QOpenGLPaintDevice;
    m_paintDevice->setSize( size() );

    m_context->doneCurrent();
    }

    void Draw() {
    if( !isExposed() )
    return;

    m_context->makeCurrent( this );

    QPainter painter( m_paintDevice );
    painter.beginNativePainting();

    glClearColor( 1.0f, 1.0f, 1.0f, 0 );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );

    for( auto unitWItr = m_units.begin(); unitWItr != m_units.end(); ) {
    UnitPtr unit = unitWItr->lock();

    if( unit.get() != NULL ) {
    // unit is only on list, if asset is accessible with formally set assetId
    Asset *asset = m_assets.at( unit->body->assetId );
    painter.drawPixmap( unit->kinematic->pos.getX(), unit->kinematic->pos.getY(), unit->body->width, unit->body->height , *asset->pixmap );
    }
    else {
    // if unit is not valid anymore, delete from draw list
    unitWItr = m_units.erase( unitWItr );
    continue;
    }

    if( unitWItr != m_units.end() )
    ++unitWItr;
    }

    painter.endNativePainting();
    m_context->swapBuffers( this );
    m_context->doneCurrent();
    }
    @

    It would be great, if you can help me. Thanks!



  • Hi,

    in order to discover memory leaks I suggest you to use "valgrind":http://valgrind.org/.


Log in to reply
 

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