Render window freezes after clicking close button (C++, VTK 9.4)

I have updated to VTK 9.4 from VTK 9.1 and have since had the following issue arise…

I have a vtkRenderWindowInteractor that includes an UpdateCallback to periodically render the window with new simulation data. All is well until I attempt to close the associated render window either during, or at the end of the simulation. In VTK 9.1, the window would close without issue. With VTK 9.4, the window freezes and gives me the following error at the end of the simulation:

X Error of failed request: BadAccess (attempt to access private resource denied)
Major opcode of failed request: 148 (GLX)
Minor opcode of failed request: 5 (X_GLXMakeCurrent)
Serial number of failed request: 157
Current serial number in output stream: 157

I get the same issue if I add an ExitEvent observer and manually call interactor->TerminateApp().

If anybody has any suggestions as to how I can fix the issue I would greatly appreciate it. I am running Ubuntu 22.04 on WSL 2 and can provide more code if necessary. Thanks!

A lot has changed in the X11 code for VTK between 9.1 and 9.4. But specifically for TerminateApp, the following info might be relevant:

  • In VTK 9.1, a call to renderWindow->Finalize() was added to vtkXRenderWindowInteractor->TerminateApp(). This change was a break with tradition, because in VTK 8 and VTK 9.0, TerminateApp() just sent an event to the X11 loop telling the loop to break, causing the main program to continue from the line after the interactor->Start() call.
  • The VTK 9.1 X11 interactor also differed from the Win32 and macOS ones, since those interactors didn’t call Finalize() in TerminateApp(). They just broke the event loop in TerminateApp(), same as the X11 interactor had done prior to VTK 9.1.

In VTK 9.4, the Finalize() call was removed from the X11 interactor TerminateApp() to restore the X11 behaviour to be more like it had been in VTK 8, and to make it behave the same as the Win32 and macOS interactors.

So that might explain part of the difference you’re seeing with closing the window on X11. But it doesn’t directly explain the X error or the freeze. The most useful thing would be a stack trace to show where the MakeCurrent() that generates the error is.

If you can send a small (but runnable) part of your program that demonstrates the error, someone here can do the debugging. Or you can modify a simple VTK example like the CylinderExample so that it generates the same error.

2 Likes

Hi David,

Thanks very much for your very helpful and informative response. Adding a call to Finalize() does indeed restore the previous behaviour, i.e., the window now correctly closes and doesn’t hang.

With regard to the X error: I suspect this was from accidentally trying to render from a (non-main) thread, which I have now fixed.

When I get a few minutes, I will provide details on the behaviour of the Cylinder Example.

Kind regards.