Results 1 to 1 of 1

Thread: QGraphicsScene + OpenGL leak (Specifically QGLContext::getProcAddress)

  1. #1
    Join Date
    Sep 2010
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Question QGraphicsScene + OpenGL leak (Specifically QGLContext::getProcAddress)

    I'd previously written a basic UI using mostly raw OpenGL which I'm now re-writing using QGraphicsScene for a number of reasons (mouse handling etc).

    I've been struggling with a memory leak and think I've tracked it down to Qt, rather than my own code, below is a minimal example which produces the leak on Mac OS 10.6.4 and 10.6.5.

    main.cpp:

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <QtGui>
    3. #include <QGraphicsView>
    4. #include <QtOpenGL/QGLWidget>
    5. #include <QtOpenGL/QGLFormat>
    6.  
    7. #include "mygraphicsscene.h"
    8.  
    9. int main(int argc, char *argv[])
    10. {
    11. QApplication a(argc, argv);
    12.  
    13. MyGraphicsScene *scene = new MyGraphicsScene;
    14.  
    15. view->setViewport(new QGLWidget());
    16. view->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
    17. // NoViewPortUpdate has the same effect
    18.  
    19. view->setScene(scene);
    20.  
    21. view->show();
    22.  
    23. view->resize(1024,768);
    24.  
    25. return a.exec();
    26. }
    To copy to clipboard, switch view to plain text mode 

    mygraphicsscene.h:

    Qt Code:
    1. #ifndef MYGRAPHICSSCENE_H
    2. #define MYGRAPHICSSCENE_H
    3.  
    4. #include <QGraphicsScene>
    5. #include <QTimer>
    6.  
    7. class MyGraphicsScene : public QGraphicsScene {
    8.  
    9. Q_OBJECT
    10.  
    11. public:
    12.  
    13. explicit MyGraphicsScene(QObject *parent = 0);
    14. void drawBackground(QPainter *painter, const QRectF &rect);
    15. void drawForeground(QPainter *painter, const QRectF &rect);
    16.  
    17. public slots:
    18.  
    19. void refresh();
    20.  
    21. protected:
    22.  
    23. QTimer *_refresher;
    24.  
    25. int _frame;
    26. };
    27.  
    28.  
    29. #endif // MYGRAPHICSSCENE_H
    To copy to clipboard, switch view to plain text mode 

    mygraphicsscene.cpp:

    Qt Code:
    1. #include "MyGraphicsScene.h"
    2.  
    3. #include <QtCore>
    4. #include <QtGlobal>
    5. #include <QPainter>
    6. #include <QPaintEngine>
    7. #include <QGraphicsItem>
    8. #include <QGraphicsProxyWidget>
    9. #include <QGLWidget>
    10.  
    11. MyGraphicsScene::MyGraphicsScene(QObject *parent) : QGraphicsScene(parent) {
    12.  
    13. _frame = 0;
    14.  
    15. _refresher = new QTimer();
    16. _refresher->setInterval(40); // Update 25FPS
    17. _refresher->setSingleShot(false);
    18.  
    19. connect(_refresher,SIGNAL(timeout()),this,SLOT(refresh()));
    20.  
    21. _refresher->start();
    22. }
    23.  
    24. void MyGraphicsScene::drawBackground(QPainter *painter, const QRectF &rect) {
    25.  
    26. }
    27.  
    28. void MyGraphicsScene::drawForeground(QPainter *painter, const QRectF &rect) {
    29.  
    30. }
    31.  
    32. void MyGraphicsScene::refresh() {
    33.  
    34. ++_frame;
    35. this->update();
    36.  
    37. }
    To copy to clipboard, switch view to plain text mode 

    Have I done something wrong or is this a problem with Qt itself?

    The first 2 screenshots are from Instruments.app showing the memory leak. It steadily grows by 100KB every 20 seconds or so.

    The third attachement shows the vast amount of memory allocated by the code above after just 2MB of leaks (Left to Right: CPU%, Threads, Real Mem). I don't know what's consuming all of that (surely the Qt libraries are less than 20MB?).

    Any ideas?

    Thanks

    Dan
    Attached Images Attached Images

Similar Threads

  1. Replies: 1
    Last Post: 2nd September 2009, 14:07
  2. Saving QGraphicsScene with OpenGL to image
    By elbaschid in forum Qt Programming
    Replies: 1
    Last Post: 12th March 2009, 20:32
  3. OpenGL texture on QGraphicsScene background
    By Ovnan in forum Qt Programming
    Replies: 5
    Last Post: 11th July 2008, 10:39
  4. Using QGraphicsScene instead of OpenGL
    By ntp in forum Qt Programming
    Replies: 2
    Last Post: 7th April 2008, 21:16
  5. OpenGL show image from buffer memory leak[SOLVED]
    By ^NyAw^ in forum Qt Programming
    Replies: 0
    Last Post: 30th January 2008, 16:21

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.