Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Memory Leak in Draw method with QPainter and QOpenGLPaintDevice

Memory Leak in Draw method with QPainter and QOpenGLPaintDevice

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kane
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      Hi,

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

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved