SIGSEGV in XSync () from /lib/x86_64-linux-gnu/libX11.so.6 on Ubuntu 20.04 WSL

I’m using Ubuntu WSL, and I have installed VTK 9.0.1. I get the error when running the following code.

obj.h file:

    vtkSmartPointer<vtkRenderWindow> ren_win_;
    vtkSmartPointer<vtkRenderWindowInteractor> interactor_;
    vtkSmartPointer<vtkRendererCollection> renders_;
    vtkSmartPointer<vtkRenderWindowInteractor> interactor_;

obj.cpp file:

	this->ren_win_ = vtkSmartPointer<vtkRenderWindow>::New();
    vtkNew<vtkGenericOpenGLRenderWindow> rw;
    ren_win_ = rw;
	this->ren_win_->SetWindowName("Visualizer");
	// create render collection
	this->renders_ = vtkSmartPointer<vtkRendererCollection>::New();
	// create interactor
	this->interactor_ = vtkSmartPointer<vtkRenderWindowInteractor>::New();
	// create default renderer
	vtkSmartPointer<vtkRenderer> default_ren = vtkSmartPointer<vtkRenderer>::New();
	this->renders_->AddItem(default_ren);
	// setup interactor
	interactor_->SetRenderWindow(this->ren_win_);
	interactor_->SetDesiredUpdateRate(30.0);
	interactor_->Initialize(); //***RAISES THE ERROR ***

The vtkGenericOpenGLRenderWindow cannot be used in this way. According to its documentation,

vtkGenericOpenGLRenderWindow provides a skeleton for implementing
a render window using one's own OpenGL context and drawable.

This means that it does not provide an OpenGL context. You must create an OpenGL context by other means (for example, with Qt) and then vtkGenericOpenGLRenderWindow will allow VTK to use that context.

In your case, I think you should just use vtkRenderWindow. Did you already try that, and did it fail? If so, please give details about how you built your project. You might not have linked to all the necessary libraries.

I also tried the following (without calling vtkGenericOpenGLRenderWindow) and still crashed with the exact same error.

this->ren_win_ = vtkSmartPointer<vtkRenderWindow>::New();
this->ren_win_->SetWindowName("ngp Visualizer");
// create render collection
this->renders_ = vtkSmartPointer<vtkRendererCollection>::New();
// create interactor
this->interactor_ = vtkSmartPointer<vtkRenderWindowInteractor>::New();
// create default renderer
vtkSmartPointer<vtkRenderer> default_ren = vtkSmartPointer<vtkRenderer>::New();
this->renders_->AddItem(default_ren);
// setup interactor
interactor_->SetRenderWindow(this->ren_win_);
interactor_->SetDesiredUpdateRate(30.0);
interactor_->Initialize();

I built the project using Visual Studio and all the dependencies seem to be satisfied. I think it may be likely that the problem is how VTK was built. I’m also having issues just running this example.

CylinderExample vtkXOpenGLRenderWindow error in C++ - Support - VTK

If you want to use WSL you have to use the compiler that comes with the Linux distribution you are using rather than Visual Studio.

Visual Studio, in this case, is configured to use the Linux cmake, ninja, C++, etc compilers.

So I managed to run the CylinderExample from WSL using the VcXsrv as my X-server. But I still get the same same XSync error when trying to run to run from Visual Studio, but if I run the exact same executable from the terminal then it successfully renders.

THIS IS A VISUAL STUDIO BUG!!!