January 13, 2012

strattonbrazil strattonbraz..
Lab Rat
3 posts

[SOLVED] Qt app crashing calling QPainter begin() - segfaults internally calling glCreateShader

 

I started testing my app on another machine, where I started booting it through pyside—if that makes a difference to this particular problem. Anyway, the program enters the paint() function of my QGLWidget-derived class and dies after calling begin(). Looking at the stack trace, the program is exiting inside the begin() function, where it seems to be calling glCreateShader().

  1. void PanelGL::paintGL()
  2. {
  3.     QPainter painter;
  4.     painter.begin(this); // crash here calling glCreateShader inside the Qt library
  5. ...
  6. }

If I comment out this code, I can call basic GL functions like glBegin() and glEnd(), but not higher profile calls like glCreateShader(), which also segfault. I’m already calling glewInit. If Qt’s QPainter internally calls glCreateShader(), I wouldn’t expect I would need to do anything involving OpenGL to make the begin() function work. Unless a QPainter() only works in a QGLWidget under certain profiles?

Here’s the stack trace:

  1. #0  0x00007fffebdb311e in glCreateShader () from /usr/lib64/libGL.so
  2. #1  0x00000037ba268262 in ?? () from /usr/lib64/libQtOpenGL.so.4
  3. #2  0x00000037ba268a28 in
  4. QGLShader::QGLShader(QFlags<QGLShader::ShaderTypeBit>, QGLContext
  5. const*, QObject*) ()
  6.    from /usr/lib64/libQtOpenGL.so.4
  7. #3  0x00000037ba27f199 in
  8. QGLEngineSharedShaders::QGLEngineSharedShaders(QGLContext const*) ()
  9.    from /usr/lib64/libQtOpenGL.so.4
  10. #4  0x00000037ba27fcd8 in
  11. QGLEngineSharedShaders::shadersForContext(QGLContext const*) ()
  12.    from /usr/lib64/libQtOpenGL.so.4
  13. #5  0x00000037ba27fdac in
  14. QGLEngineShaderManager::QGLEngineShaderManager(QGLContext*) ()
  15.    from /usr/lib64/libQtOpenGL.so.4
  16. #6  0x00000037ba282fb8 in QGL2PaintEngineEx::begin(QPaintDevice*) ()
  17. from /usr/lib64/libQtOpenGL.so.4
  18. #7  0x00000037b97152e0 in QPainter::begin(QPaintDevice*) () from
  19. /usr/lib64/libQtGui.so.4
  20. #8  0x00007fffef9c402d in PanelGL::paintGL (this=0x1006030) at panelgl.cpp:117
  21. #9  0x00000037ba22da60 in QGLWidget::glDraw() () from
  22. /usr/lib64/libQtOpenGL.so.4
  23. #10 0x00000037ba22d3f9 in QGLWidget::paintEvent(QPaintEvent*) () from
  24. /usr/lib64/libQtOpenGL.so.4
  25. #11 0x00000037b9619fdc in QWidget::event(QEvent*) () from
  26. /usr/lib64/libQtGui.so.4
  27. #12 0x00000037ba22f988 in QGLWidget::event(QEvent*) () from
  28. /usr/lib64/libQtOpenGL.so.4
  29. #13 0x00000037b95c9994 in QApplicationPrivate::notify_helper(QObject*,
  30. QEvent*) () from /usr/lib64/libQtGui.so.4
  31. #14 0x00000037b95ce813 in QApplication::notify(QObject*, QEvent*) ()
  32. from /usr/lib64/libQtGui.so.4
  33. #15 0x00007ffff024b5b6 in ?? () from
  34. /usr/lib64/python2.7/site-packages/PySide/QtGui.so
  35. #16 0x00000037b8f7903c in QCoreApplication::notifyInternal(QObject*,
  36. QEvent*) () from /usr/lib64/libQtCore.so.4
  37. #17 0x00000037b9615c80 in QWidgetPrivate::drawWidget(QPaintDevice*,
  38. QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*)
  39. () from /usr/lib64/libQtGui.so.4
  40. #18 0x00000037b97dc867 in QWidgetPrivate::repaint_sys(QRegion const&)
  41. () from /usr/lib64/libQtGui.so.4
  42. #19 0x00000037b960c3e4 in QWidgetPrivate::syncBackingStore() () from
  43. /usr/lib64/libQtGui.so.4
  44. #20 0x00000037b961a4fc in QWidget::event(QEvent*) () from
  45. /usr/lib64/libQtGui.so.4
  46. #21 0x00000037ba22f988 in QGLWidget::event(QEvent*) () from
  47. /usr/lib64/libQtOpenGL.so.4
  48. #22 0x00000037b95c9994 in QApplicationPrivate::notify_helper(QObject*,
  49. QEvent*) () from /usr/lib64/libQtGui.so.4
  50. #23 0x00000037b95ce813 in QApplication::notify(QObject*, QEvent*) ()
  51. from /usr/lib64/libQtGui.so.4
  52. #24 0x00007ffff024b5b6 in ?? () from
  53. /usr/lib64/python2.7/site-packages/PySide/QtGui.so
  54. #25 0x00000037b8f7903c in QCoreApplication::notifyInternal(QObject*,
  55. QEvent*) () from /usr/lib64/libQtCore.so.4
  56. #26 0x00000037b8f7caca in
  57. QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*)
  58. ()
  59.    from /usr/lib64/libQtCore.so.4
  60. #27 0x00000037b8fa7923 in ?? () from /usr/lib64/libQtCore.so.4
  61. #28 0x0000003039444a7d in g_main_context_dispatch () from
  62. /lib64/libglib-2.0.so.0
  63. #29 0x0000003039445278 in ?? () from /lib64/libglib-2.0.so.0
  64. #30 0x000000303944544c in g_main_context_iteration () from
  65. /lib64/libglib-2.0.so.0
  66. #31 0x00000037b8fa7d4f in
  67. QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>)
  68. ()
  69.    from /usr/lib64/libQtCore.so.4
  70. #32 0x00000037b966c61e in ?? () from /usr/lib64/libQtGui.so.4
  71. #33 0x00000037b8f78172 in
  72. QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) ()
  73.    from /usr/lib64/libQtCore.so.4

5 replies

January 23, 2012

karlphillip karlphillip
Lab Rat
4 posts

Any updates on this issue?

January 23, 2012

Tobias Hunger Tobias Hunger
Hobby Entomologist
3373 posts

I doubt that there will be any without a bug report [bugreports.qt.nokia.com]:-(

January 23, 2012

karlphillip karlphillip
Lab Rat
4 posts

I had a similar problem [gamedev.stackexchange.com] once and here is how I solved it: before calling glCreateShader(), which is a GLEW function, I needed to initialize the library and I wasn’t doing so.

  1.  GLenum err = glewInit();
  2.  if (err != GLEW_OK)
  3.  {
  4.   qDebug() << "paintEvent !!! glewInit failed with: " << err;
  5.   return;
  6.  }
  7.  if (!GLEW_VERSION_2_1)  // check that the machine supports the 2.1 API.
  8.  {
  9.   qDebug() << "paintEvent !!! System doesn't support GLEW_VERSION_2_1";
  10.   return;
  11.  }

Apparently, the problem reported in this thread was not caused by this issue because the user is already calling glewInit().

January 23, 2012

strattonbrazil strattonbraz..
Lab Rat
3 posts
karlphillip wrote:
I’m afraid this is not a Qt bug. It seems that strattonbrazil is trying to call glCreateShader(), which is a GLEW function, without initializing this library first. @

Hey Karl,

That’s an interesting assumption considering that I say in my original post “I’m already calling glewInit”. Anyway, if QPainter is calling glCreateShader, Qt should be calling glewInit unless Qt is shipping without libraries that it needs to perform basic operations under the hood like creating a QPainter inside a QGLWidget.

The problem was that in Qt Creator, the default run settings on my new OS set the LD_LIBRARY_PATH, which caused a consistent segfault. I could replicate this on the shell too by setting the same variable. By changing my run settings from “build” to “system” it worked fine.

January 23, 2012

karlphillip karlphillip
Lab Rat
4 posts

Thank you for the feedback. I updated my answer.

Now that you solved the problem you can add [Solved] in the beggining of the title of the question.

 
  ‹‹ Problem when exporting graphic to file after calling fitInView()      QLabel doesn’t get transparent background and editable text even so i did set the right flags ››

You must log in to post a reply. Not a member yet? Register here!