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:
Qt Code:
  1. #ifndef CUBEWIDGET_H
  2. #define CUBEWIDGET_H
  3.  
  4. #include <iostream>
  5. #include <QtGui>
  6. #include <QtOpenGl>
  7. #include <cmath>
  8.  
  9. class cubeWidget : public QGLWidget
  10. {
  11. Q_OBJECT
  12.  
  13. public:
  14. cubeWidget();
  15.  
  16. protected:
  17. void initializeGL();
  18. void paintGL();
  19. void resizeGL(int width, int height);
  20.  
  21. public slots:
  22. void rotateOneStep();
  23.  
  24. private:
  25. float rot;
  26. QImage texture;
  27. GLuint nr;
  28. };
  29. #endif
To copy to clipboard, switch view to plain text mode 

cubewidget.cpp:
Qt Code:
  1. #include "cubewidget.h"
  2.  
  3. cubeWidget::cubeWidget()
  4. : rot(0.0)
  5. {
  6. }
  7.  
  8. void cubeWidget::initializeGL()
  9. {
  10. glClearColor(0.0, 0.0, 0.0, 0.0);
  11. /*
  12. glEnable(GL_DEPTH_TEST);
  13. glEnable(GL_CULL_FACE);
  14. glEnable(GL_TEXTURE_2D);
  15.  
  16. QString s = "C:/Dokumente und Einstellungen/me/Desktop/opengl_cmyk.png";
  17. if(!texture.load(s))
  18. {
  19. std::cout << "Error loading texture!" << std::endl;
  20. exit(1);
  21. }
  22. nr = bindTexture(texture, GL_TEXTURE_2D);
  23.  
  24. */
  25. QTimer *timer = new QTimer(this);
  26. connect(timer, SIGNAL(timeout()), this, SLOT(rotateOneStep()));
  27. timer->start(10);
  28. }
  29.  
  30. void cubeWidget::rotateOneStep()
  31. {
  32. rot += 0.5;
  33. rot = rot < 360.0 ? rot : rot - 360.0;
  34. updateGL();
  35. }
  36.  
  37. void cubeWidget::paintGL()
  38. {
  39. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  40. /*
  41.   glMatrixMode(GL_MODELVIEW);
  42. glLoadIdentity();
  43.  
  44.   glRotatef(sin(rot /180.0*3.141) * 180, 1, 0, 0);
  45.   glRotatef(sin((rot+135)/180.0*3.141) * 180, 0, 1, 0);
  46.   glRotatef(sin((rot+270)/180.0*3.141) * 180, 0, 0, 1);
  47.  
  48. glBindTexture(GL_TEXTURE_2D, nr);
  49. glBegin(GL_QUADS);
  50. // vorne
  51. glTexCoord2d(0.0, 0.0);
  52. glVertex3i(-1, -1, +1);
  53. glTexCoord2d(1.0, 0.0);
  54. glVertex3i(+1, -1, +1);
  55. glTexCoord2d(1.0, 1.0);
  56. glVertex3i(+1, +1, +1);
  57. glTexCoord2d(0.0, 1.0);
  58. glVertex3i(-1, +1, +1);
  59.  
  60. // rechts
  61. glTexCoord2d(0.0, 0.0);
  62. glVertex3i(+1, -1, +1);
  63. glTexCoord2d(1.0, 0.0);
  64. glVertex3i(+1, -1, -1);
  65. glTexCoord2d(1.0, 1.0);
  66. glVertex3i(+1, +1, -1);
  67. glTexCoord2d(0.0, 1.0);
  68. glVertex3i(+1, +1, +1);
  69.  
  70. // hinten
  71. glTexCoord2d(0.0, 0.0);
  72. glVertex3i(+1, -1, -1);
  73. glTexCoord2d(1.0, 0.0);
  74. glVertex3i(-1, -1, -1);
  75. glTexCoord2d(1.0, 1.0);
  76. glVertex3i(-1, +1, -1);
  77. glTexCoord2d(0.0, 1.0);
  78. glVertex3i(+1, +1, -1);
  79.  
  80. // links
  81. glTexCoord2d(0.0, 0.0);
  82. glVertex3i(-1, -1, -1);
  83. glTexCoord2d(1.0, 0.0);
  84. glVertex3i(-1, -1, +1);
  85. glTexCoord2d(1.0, 1.0);
  86. glVertex3i(-1, +1, +1);
  87. glTexCoord2d(0.0, 1.0);
  88. glVertex3i(-1, +1, -1);
  89.  
  90. // oben
  91. glTexCoord2d(0.0, 0.0);
  92. glVertex3i(-1, +1, +1);
  93. glTexCoord2d(1.0, 0.0);
  94. glVertex3i(+1, +1, +1);
  95. glTexCoord2d(1.0, 1.0);
  96. glVertex3i(+1, +1, -1);
  97. glTexCoord2d(0.0, 1.0);
  98. glVertex3i(-1, +1, -1);
  99.  
  100. // unten
  101. glTexCoord2d(0.0, 0.0);
  102. glVertex3i(-1, -1, -1);
  103. glTexCoord2d(1.0, 0.0);
  104. glVertex3i(+1, -1, -1);
  105. glTexCoord2d(1.0, 1.0);
  106. glVertex3i(+1, -1, +1);
  107. glTexCoord2d(0.0, 1.0);
  108. glVertex3i(-1, -1, +1);
  109. glEnd();*/
  110. }
  111.  
  112. void cubeWidget::resizeGL(int width, int height)
  113. {
  114. glViewport(0, 0, (GLint)width, (GLint)height);
  115.  
  116. glMatrixMode(GL_PROJECTION);
  117. glLoadIdentity();
  118. glOrtho(-2.0, 2.0, -2.0, 2.0, 2.0, -2.0);
  119. }
  120.  
  121. int main(int argc, char **argv)
  122. {
  123. QApplication app(argc, argv);
  124.  
  125. cubeWidget cube;
  126. cube.show();
  127. return app.exec();
  128. }
To copy to clipboard, switch view to plain text mode 
I'm using QT 4.1.4 for windows with MingW compiler(3.4.2)