QOpenGLWidget stops repainting on update()

谁说胖子不能爱 提交于 2019-12-07 20:04:00

问题


I have a custom QDialog which contains a hierarchy with 4 separate instances of QOpenGLWidget.

Each of these QOpenGLWidget's has its own GL context, and renders a different scene.

I have a loop which calls update() (the recommended method for repainting them) on each QOpenGLWidget regularly (the focused one more regularly, however I think this is irrelevant to the problem).

My problem is that eventually after random amounts of time (sometime it happens quickly, other times it won't happen for 10+ mins), one or more QOpenGLWidget's will stop repainting when update() is called.

I have however noticed that resizing the stalled QOpenGLWidget causes a single repaint event to be triggered.

I can see with the debugger that update() is being called on all the QOpenGLWidget's, but this is never triggering paintGL() (the repaint method) for the stalled widgets. and that updatesEnabled() always returns true, regardless of wether update() is triggering repaints or not. QT also isn't printing any errors or warnings to console.

The dialog containing these widgets is running in a separate thread to the one that triggers update(), so I can't call repaint() directly (without writing my own event loop).

Adding QApplication::sync() to the method that triggers update() doesn't make a difference either.

I'm inclined to think it occurs more when there's less ram available, however less ram is in the order of 800mb, and the application uses significantly less than that. So my gut is probably wrong.

I'm not a big user of QT, so I'm not too sure where to go from here debugging the issue further, any suggestions would be welcome. Given the reproducibility of the error involves waiting an unknown length of time and a more complex and multi-threaded project, can't imagine there would be much benefit to me attempting to reproduce the bug with a small snippet of code.


Update:

Just ran into exactly the same issue when calling update() on a QGraphicsScene, however it was occurring after only a couple of updates every time.

Found this suggestion to instead update the viewport with viewport()->update() and it appears to have fixed the problem.

QOpenGLWidget however doesn't have a viewport to update in the same way.

来源:https://stackoverflow.com/questions/40865672/qopenglwidget-stops-repainting-on-update

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!