<div dir="ltr"><div>Hello everyone,<br></div><div><br></div><div>I am receiving some errors on cleanup of my application. I am using Python 3.5.4 with PyQt5 and VTK 8.1 (Conda installed). I have a basic GUI with two widgets used with VTK, each one instantiates a QVTKRenderWindowInteractor, vtkRenderer and vtkRenderWindow like you'd expect. Here is a simplified test case I have made: <a href="https://pastebin.com/EwuHZBFG">https://pastebin.com/EwuHZBFG</a>. For the test case, here is the output that is generated:</div><div><br></div><div><i><b>destructor</b></i></div><div><i><b>SliceWidget_del1</b></i></div><div><i><b>SliceWidget_del2</b></i></div><div><i><b>SliceWidget_del3</b></i></div><div><i><b>SliceWidget_del4</b></i></div><div><i><b><br></b></i></div><div><i><b>SliceWidget_del1</b></i></div><div><i><b>SliceWidget_del2</b></i></div><div><i><b>ERROR: In ..\Rendering\OpenGL2\vtkWin32OpenGLRenderWindow.cxx, line 227</b></i></div><div><i><b>vtkWin32OpenGLRenderWindow (00000258F6471A00): wglMakeCurrent failed in MakeCurrent(), error: The handle is invalid.</b></i></div><div><i><b><br></b></i></div><div><i><b><br></b></i></div><div><i><b>ERROR: In ..\Rendering\OpenGL2\vtkWin32OpenGLRenderWindow.cxx, line 87</b></i></div><div><i><b>vtkWin32OpenGLRenderWindow (00000258F6471A00): wglMakeCurrent failed in Clean(), error: 6</b></i></div><div><i><b><br></b></i></div><div><i><b>SliceWidget_del3</b></i></div><div><i><b>SliceWidget_del4</b></i></div><div><br></div><div>What this indicates is that on vtkRenderWindow.Finalize(), it is failing on the <b>SECOND</b> destructor. So naturally, I removed the second render window and found it works fine on applications with one render window.</div><div><br></div><div>After extensive debugging, I have found that this issue can be resolved if vtkRenderWindow.Finalize() is called for both windows before the interactor, renderWindow and renderer are destroyed. At lines 71 and 72 in the test case if you uncomment them, then the code works fine.</div><div><br></div><div>In other words, here is a basic example</div><div><b><i># This WILL work</i></b></div><div><b><i>sliceWidget1.Finalize()</i></b></div><div><b><i>sliceWidget2.Finalize()</i></b></div><div><b><i><br></i></b></div><div><b><i>delete sliceWidget1 (This will delete interactor, renderer and renderWindow)</i></b></div><div><b><i>delete sliceWidget2 (This will delete interactor, renderer and renderWindow)</i></b></div><div><br></div><div><br></div><div><b><i># This WILL NOT work</i></b></div><div><b><i>delete sliceWidget1 (This will delete interactor, renderer and renderWindow)</i></b></div><div><b><i>sliceWidget1.Finalize()</i></b></div><div><b><i>delete sliceWidget2 (This will delete interactor, renderer and renderWindow)</i></b></div><div><b><i>sliceWidget2.Finalize()</i></b></div><div><br></div><div>Can anyone offer any assistance on where in VTK this may be causing an issue? My initial thoughts is that upon destruction of one of the VTK objects, the context device ID is destroyed and thus cannot be used in the second Finalize() call. I don't have much familiarity in the VTK source code, so I was fairly lost in trying to pinpoint the issue.</div><div><br></div><div>Thanks,</div><div>Addison</div></div>