How to properly use multiple QVTKOpenGLNativeWidgets

I’m porting our system from vtk7.1.1 to 8.2 and have been encountering several annoying issues.
We have multiple viewports each with a QVTKOpenGLNativeWidget.
Rendering works okay (with some issues with alpha) but I was getting crashes occasionally when removing vtkActors from the renderer.

Digging into it I found that QVTKOpenGLNativeWidgetObserver::Execute() in the case vtkCommand::WindowMakeCurrentEvent: was causing the crash. I presume that the context or the surface is invalid because it’s outside of the render call. I had no idea how to fix this except to use QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); before app initialization.
This doesn’t seem right. I’m wondering what could be done differently to make multiple QVTKOpenGLNativeWidgets work well.


Hi Ben,

For what it’s worth, we also recently ported our app to 8.2. We’re using multiple QVTKOpenGLNativeWidgets (four of them for a couple of places where we have color/opacity editors for volume rendering, and two of them in which we do volume and polydata rendering). We have not run into the issue you describe (on Linux/Windows/macOS).

In the two volume rendering widgets, we regularly add/remove actors/volumes.

Have you tried to make a minimal test case that crashes? It would help to see how you set up the widgets/renderers/windows.

Hi Elvis,
Thanks for the feedback.
I’ll try to dig deeper later and put together a minimal example.
For now, my workaround seems to work so I need to continue with the port.
There’s a lot of tweaks that seem to need to be set.
PS. the commit connected to Translucent assemblies in 8.2.0 helped a lot!