Crash when using Offscreen Rendering inside Qt Application
I have written a library, which shall produce some rendering of scenes into images using VTK (no actual interactive 3D windows).
Inside the library's cpp module, I have initialized the rendering backend:
VTK_MODULE_INIT(vtkRenderingOpenGL2)
VTK_MODULE_INIT(vtkRenderingFreeType)
VTK_MODULE_INIT(vtkInteractionStyle)
and somewhere else, I create a renderWindow for offscreen rendering:
renderer_ = vtkSmartPointer<vtkRenderer>::New();
renderWindow_ = vtkSmartPointer<vtkRenderWindow>::New();
renderWindow_->AddRenderer(renderer_);
renderWindow_->OffScreenRenderingOn();
renderWindow_->SetSize(1920, 1440);
renderer_->SetBackground(1, 1, 1); // Background color white
I have two executables from which the library is used: one command line tool and a Qt based GUI application. Using the library from the command line tool works all as expected. When called from the GUI application, the programm segfaults when the Render function is called with the following stack trace:
1 glGetFloatv
2 vtkOpenGLRenderWindow::OpenGLInitContext()
3 vtkOpenGLRenderWindow::OpenGLInit()
4 vtkOSOpenGLRenderWindow::Start()
5 vtkRenderWindow::DoStereoRender()
6 vtkRenderWindow::Render()
7 vtkOpenGLRenderWindow::Render()
...
some more informations:
- I use VTK8.2.0 (which comes along and is compiled together with Paraview 5.6)
- Paraview was configured with these flags:
-DCMAKE_BUILD_TYPE=Release -DPARAVIEW_BUILD_QT_GUI=OFF -DPARAVIEW_ENABLE_CATALYST=ON -DPARAVIEW_ENABLE_PYTHON=ON -DPARAVIEW_INSTALL_DEVELOPMENT_FILES=ON -DBUILD_TESTING=OFF -DVTK_OPENGL_HAS_OSMESA=ON -DVTK_USE_X=OFF -DVTK_DEFAULT_RENDER_WINDOW_OFFSCREEN=ON -DOPENGL_INCLUDE_DIR=IGNORE -DOPENGL_gl_LIBRARY=IGNORE -DOPENGL_xmesa_INCLUDE_DIR=IGNORE
I suspect there is some conflict between the OpenGL usage of Qt and VTK. Maybe there is some other rendering backend required in this case?
I am grateful for any suggestions on how to avoid the segfault!
Regards, Hannes