I’m trying to use the relatively new class vtkQWidgetWidget in SlicerVR (to show a Qt widget in VR that can be manipulated using a laser pointer), and I keep getting a crash when rendering the scene after adding the prop to the renderer.
I checked that the VTK test TestQWidgetWidget works, and started from that code. When I changed the creation of the Qt widget on the stack to the heap, then it crashed.
It seems that the crash happens on the first render after adding the prop. This is the log after the render call:
Python console user input: r.Render() Generic Warning: In C:\d\S4D\VTK\Rendering\OpenGL2\vtkOpenGLState.cxx, line 182 Error in cache state for GL_SCISSOR_BOX
Then it crashes. Not fully deterministically though: when I debug into the code and step slowly, it many times does not crash. Also in release mode sometimes it seems like crashing (few seconds wait), but then shows the widget as expected.
My first question is whether anybody actually used the vtkQWidgetWidget class in a real project, other than the test?
I use it in PV and it seems fine. The cache state error is I think still there (I forget if I fixed it or not) but shouldn’t be a real problem.
Thanks! I’ll check out the PV code and see how it’s done there.
The ParaView code that uses vtkQWidgetWidget seems equivalent to what I try to do, so unfortunately there are no clues there. A simple QWidget is created on the heap, and it’s set after the usual initialization calls to the widget.
It is quite strange though that both my code and the VTK test has the same issue: if the QWidget is created on the stack then they work, otherwise they crash.
If you replace
QPushButton hello( "Hello world!", 0 );
QPushButton* hello = new QPushButton( "Hello world!", 0 );
widget->SetWidget( &hello );
widget->SetWidget( hello );
then the crash should occur on the VTK test VTK::GUISupportQtCxx-TestQVTKOpenGLWidgetQWidgetWidget (TestQWidgetWidget.cxx).
Could somebody please confirm this? Thank you!
I just checked that on master (windows nvidia qt 5.9.4) and it seemed fine. Which doesn’t mean everything is fine, just that my system seems to not show the issue. There have been some fixes to that class in the past month to address some rendering issues as well.
Thanks for checking! I verified the same just this morning: the crash in the VTK test in debug mode doesn’t happen with the latest version. However, I still got the crash in SlicerVR (after cherry picking those commits on Slicer’s VTK). I’ve started clean builds also in release mode and will try to isolate the issue. I’ll let you know.
Using the release build of the latest VTK, the QWidgetWidget tests seem OK even if instantiating the QWidget on the heap.
I cherry-picked two of your commits that were obviously related to this class, see the top two commits here: https://github.com/cpinter/VTK/tree/slicervr-vtkqwidgetwidget-crash-fix
(this is based on this branch https://github.com/Slicer/VTK/tree/slicer-v8.2.0-2018-10-02-74d9488523, deviated from VTK proper October 2, 2018).
The crash I’m getting when I try to do the same thing that the TestQWidgetWidget does yields a call stack that only contains event loop calls, so it doesn’t tell much.
|Qt5Cored.dll!QEventDispatcherWin32::processEvents(QFlags flags) Line 646
|qwindowsd.dll!QWindowsGuiEventDispatcher::processEvents(QFlags flags) Line 74
|Qt5Cored.dll!QEventLoop::processEvents(QFlags flags) Line 135
|Qt5Cored.dll!QEventLoop::exec(QFlags flags) Line 212
|Qt5Cored.dll!QCoreApplication::exec() Line 1332
|Qt5Guid.dll!QGuiApplication::exec() Line 1688
|Qt5Widgetsd.dll!QApplication::exec() Line 2918
|qSlicerBaseQTCore.dll!qSlicerCoreApplication::exec() Line 775
Can you think of other commits that may be related to how the graphics resources are managed that may be related to this crash? I’d backport those too in case they fix my issue. Or if you have any other suggestions please let me know. Thank you!
A year ago is a pretty big diff, lots of potential side effects. I know there was a big rework of the Qt interface in this MR https://gitlab.kitware.com/vtk/vtk/merge_requests/5214