PDA

View Full Version : Crash when minimizing OpenGL widget



MistaPain
6th October 2006, 19:35
I have created a very simple OpenGL application which displays a spinning textured cube. Everything works fine except that it crashes when minimizing the window. I've tracked down the error to the call to glClear(), but I've no idea why it's this function call which fails.
I've commented out several lines of code which do the actual rendering of the cube but the error still occurs. :(

cubewidget.h:


#ifndef CUBEWIDGET_H
#define CUBEWIDGET_H

#include <iostream>
#include <QtGui>
#include <QtOpenGl>
#include <cmath>

class cubeWidget : public QGLWidget
{
Q_OBJECT

public:
cubeWidget();

protected:
void initializeGL();
void paintGL();
void resizeGL(int width, int height);

public slots:
void rotateOneStep();

private:
float rot;
QImage texture;
GLuint nr;
};
#endif

cubewidget.cpp:

#include "cubewidget.h"

cubeWidget::cubeWidget()
: rot(0.0)
{
}

void cubeWidget::initializeGL()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
/*
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);

QString s = "C:/Dokumente und Einstellungen/me/Desktop/opengl_cmyk.png";
if(!texture.load(s))
{
std::cout << "Error loading texture!" << std::endl;
exit(1);
}
nr = bindTexture(texture, GL_TEXTURE_2D);

*/
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(rotateOneStep()));
timer->start(10);
}

void cubeWidget::rotateOneStep()
{
rot += 0.5;
rot = rot < 360.0 ? rot : rot - 360.0;
updateGL();
}

void cubeWidget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/*
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glRotatef(sin(rot /180.0*3.141) * 180, 1, 0, 0);
glRotatef(sin((rot+135)/180.0*3.141) * 180, 0, 1, 0);
glRotatef(sin((rot+270)/180.0*3.141) * 180, 0, 0, 1);

glBindTexture(GL_TEXTURE_2D, nr);
glBegin(GL_QUADS);
// vorne
glTexCoord2d(0.0, 0.0);
glVertex3i(-1, -1, +1);
glTexCoord2d(1.0, 0.0);
glVertex3i(+1, -1, +1);
glTexCoord2d(1.0, 1.0);
glVertex3i(+1, +1, +1);
glTexCoord2d(0.0, 1.0);
glVertex3i(-1, +1, +1);

// rechts
glTexCoord2d(0.0, 0.0);
glVertex3i(+1, -1, +1);
glTexCoord2d(1.0, 0.0);
glVertex3i(+1, -1, -1);
glTexCoord2d(1.0, 1.0);
glVertex3i(+1, +1, -1);
glTexCoord2d(0.0, 1.0);
glVertex3i(+1, +1, +1);

// hinten
glTexCoord2d(0.0, 0.0);
glVertex3i(+1, -1, -1);
glTexCoord2d(1.0, 0.0);
glVertex3i(-1, -1, -1);
glTexCoord2d(1.0, 1.0);
glVertex3i(-1, +1, -1);
glTexCoord2d(0.0, 1.0);
glVertex3i(+1, +1, -1);

// links
glTexCoord2d(0.0, 0.0);
glVertex3i(-1, -1, -1);
glTexCoord2d(1.0, 0.0);
glVertex3i(-1, -1, +1);
glTexCoord2d(1.0, 1.0);
glVertex3i(-1, +1, +1);
glTexCoord2d(0.0, 1.0);
glVertex3i(-1, +1, -1);

// oben
glTexCoord2d(0.0, 0.0);
glVertex3i(-1, +1, +1);
glTexCoord2d(1.0, 0.0);
glVertex3i(+1, +1, +1);
glTexCoord2d(1.0, 1.0);
glVertex3i(+1, +1, -1);
glTexCoord2d(0.0, 1.0);
glVertex3i(-1, +1, -1);

// unten
glTexCoord2d(0.0, 0.0);
glVertex3i(-1, -1, -1);
glTexCoord2d(1.0, 0.0);
glVertex3i(+1, -1, -1);
glTexCoord2d(1.0, 1.0);
glVertex3i(+1, -1, +1);
glTexCoord2d(0.0, 1.0);
glVertex3i(-1, -1, +1);
glEnd();*/
}

void cubeWidget::resizeGL(int width, int height)
{
glViewport(0, 0, (GLint)width, (GLint)height);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2.0, 2.0, -2.0, 2.0, 2.0, -2.0);
}

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

cubeWidget cube;
cube.show();
return app.exec();
}
I'm using QT 4.1.4 for windows with MingW compiler(3.4.2)

jpn
6th October 2006, 20:17
Maybe something Windows specific. Doesn't crash for me on X11 (with Qt 4.1.4 nor 4.2.0).

MistaPain
6th October 2006, 20:44
Maybe something Windows specific. Doesn't crash for me on X11 (with Qt 4.1.4 nor 4.2.0).Thank you for this information. Unfortunaltely, I don't have another compiler available for Windows with which I could test the app to see if it's a compiler issue.

Anyway, it seems to have something to do with the timer and the call to updateGL(). If I don't use a time or if I don't call update(), it all okay.

edit: The windows system logs says it's a divide by zero error.

jpn
6th October 2006, 21:19
Doesn't crash for me with any of these configurations either:

VS2005 + Qt 4.2.0
VS2005 + Qt 4.1.4
MinGW + Qt 4.2.0

MistaPain
7th October 2006, 16:30
Now I've upgraded to QT 4.2.0 und reinstalled MinGW. But that diddn't help :crying:

Doesn't crash for me with any of these configurations either:

VS2005 + Qt 4.2.0
VS2005 + Qt 4.1.4
MinGW + Qt 4.2.0
Aaah, I don't get it! What the hell am I doing wrong? :confused: Any ideas?

btw: I'm using Win2k SP4.

MistaPain
7th October 2006, 16:58
OMG, I can't believe this. Now I know what was wrong.

It was a bug in the graphics driver. After upgrading to Catalyst 6.2 for my Radeon 9700 nonPro, it all works nicely now. Before that, I was using a rather old Cat (don't know exactly; I guess something like 4.x).

Thank you all for your time.