Crash when using vtkQWidgetWidget

Hi all,

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:
(this is based on this branch, 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 C++
qwindowsd.dll!QWindowsGuiEventDispatcher::processEvents(QFlags flags) Line 74 C++
Qt5Cored.dll!QEventLoop::processEvents(QFlags flags) Line 135 C++
Qt5Cored.dll!QEventLoop::exec(QFlags flags) Line 212 C++
Qt5Cored.dll!QCoreApplication::exec() Line 1332 C++
Qt5Guid.dll!QGuiApplication::exec() Line 1688 C++
Qt5Widgetsd.dll!QApplication::exec() Line 2918 C++
qSlicerBaseQTCore.dll!qSlicerCoreApplication::exec() Line 775 C++

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

1 Like