Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memory leak in a simple opengl program

Tags:

qt

opengl

I've wrote a simple opengl program to make some test. Here is the program:

#include <QApplication>
#include <QGLWidget>
#include <QTimer>
#include <glut.h>

class Ren : public QGLWidget
{
public:
 Ren() : QGLWidget() 
 {
  timer = new QTimer(this);
  connect(timer, SIGNAL(timeout()),
   this, SLOT(updateGL()));
 }

 void startUpdateTimer()
 {
  timer->start(40);
 }

 void initializeGL()
 {
  glShadeModel(GL_SMOOTH);      
  glClearColor(0.5f, 0.5f, 0.5f, 0.0f);     
  glClearDepth(1.0f);       
  glEnable(GL_DEPTH_TEST);   
 }

 void resizeGL(int width, int height)
 {
  if(height == 0){
   height = 1;
  }
  glViewport(0, 0, width, height);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  GLfloat aspectRatio = (GLfloat)width / (GLfloat)height;
  gluPerspective(60.0, aspectRatio, 0.01, 10000.0);
  glMatrixMode(GL_MODELVIEW);
 }

 void paintGL()
 {
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glLoadIdentity();

  gluLookAt(0, 0, 1, 0, 0, 0, 0, 1, 0);

  glColor3d(1, 0, 0);
  glutSolidCube(0.3);
 }

 QTimer *timer;
};

int main(int argc, char **argv)
{
 QApplication app(argc, argv);

 Ren r;
 r.show();
 r.startUpdateTimer();

 return app.exec();
}

The problem is that the application is leaking memory, when timer is active. For leak detection I used windows task manager.

like image 835
Andrew Avatar asked Jul 15 '26 00:07

Andrew


1 Answers

Sorry. I was wrong. There is now leaking. The 'leaking' is stopped after some time (about a minute). I think it's a kind of opengl or Qt job. I've looked some Qt examples and saw the same thing in Textures example. The same thing is happened, if I change another examples to draw something else in PaintGL() function (depending on it there is different 'leaking' time.

like image 84
Andrew Avatar answered Jul 18 '26 02:07

Andrew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!