Results 1 to 6 of 6

Thread: Crash when minimizing OpenGL widget

  1. #1
    Join Date
    Oct 2006
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Crash when minimizing OpenGL widget

    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)

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Crash when minimizing OpenGL widget

    Maybe something Windows specific. Doesn't crash for me on X11 (with Qt 4.1.4 nor 4.2.0).
    J-P Nurmi

  3. #3
    Join Date
    Oct 2006
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Crash when minimizing OpenGL widget

    Quote Originally Posted by jpn View Post
    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.
    Last edited by MistaPain; 6th October 2006 at 22:18.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Crash when minimizing OpenGL widget

    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
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    MistaPain (8th October 2006)

  6. #5
    Join Date
    Oct 2006
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Crash when minimizing OpenGL widget

    Now I've upgraded to QT 4.2.0 und reinstalled MinGW. But that diddn't help
    Quote Originally Posted by jpn View Post
    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? Any ideas?

    btw: I'm using Win2k SP4.

  7. #6
    Join Date
    Oct 2006
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Crash when minimizing OpenGL widget

    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.

Similar Threads

  1. When is the best time to delete a QCanvasItem
    By irudkin in forum Qt Programming
    Replies: 12
    Last Post: 8th March 2007, 22:28
  2. Pin/Unpin Dock Widget
    By charlesD in forum Newbie
    Replies: 1
    Last Post: 21st June 2006, 07:57
  3. minimize child widget
    By sreedhar in forum Qt Programming
    Replies: 5
    Last Post: 15th May 2006, 13:02
  4. Replies: 4
    Last Post: 24th March 2006, 23:50
  5. [Qt 4.1.0] Split a widget on demand
    By Townk in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 15:16

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.