# How to properly use multiple QVTKOpenGLNativeWidgets

**URL:** https://discourse.vtk.org/t/how-to-properly-use-multiple-qvtkopenglnativewidgets/1081
**Category:** Development
**Created:** [June 4, 2019, 3:54pm UTC](https://discourse.vtk.org/t/how-to-properly-use-multiple-qvtkopenglnativewidgets/1081 "2019-06-04T15:54:54Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![bschleimer](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/b2d939/32.png) [@bschleimer](https://discourse.vtk.org/u/bschleimer)
#### Post date: [June 4, 2019, 3:54pm UTC](https://discourse.vtk.org/t/how-to-properly-use-multiple-qvtkopenglnativewidgets/1081/1 "2019-06-04T15:54:54Z")

</div>

Hi,  
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.

Thanks!  
Ben

---

<div class="post-metadata">

### Author: ![estan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/estan/32/460_2.png) [@estan](https://discourse.vtk.org/u/estan)
#### Post date: [June 4, 2019, 7:20pm UTC](https://discourse.vtk.org/t/how-to-properly-use-multiple-qvtkopenglnativewidgets/1081/2 "2019-06-04T19:20:30Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![bschleimer](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/b2d939/32.png) [@bschleimer](https://discourse.vtk.org/u/bschleimer)
#### Post date: [June 5, 2019, 6:06pm UTC](https://discourse.vtk.org/t/how-to-properly-use-multiple-qvtkopenglnativewidgets/1081/3 "2019-06-05T18:06:03Z")

</div>

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](https://discourse.vtk.org/t/translucent-assemblies-in-8-2-0/419/5) helped a lot!
