Crash Using Vtk in QML

When migrating from qt5.9 vtk8 ubuntu 16 to qt5.15 vtk8 ubuntu 20 we started to have crashes within VTK when rendering the scene.
We are using

Using vtk debug it looks like it’s pointing to this line:
I am not sure where to start … any ideas?
Our stack trace is the following:
1 vtkTransformConcatenation::GetMaxMTime() 0x7ffff5e73354
2 vtkTransform::GetMTime() 0x7ffff5e84dad
3 vtkProp3D::GetUserTransformMatrixMTime() 0x7ffff6cc8bde
4 vtkProp3D::GetMTime() 0x7ffff6cca34d
5 vtkActor::GetMTime() 0x7ffff6c33773
6 vtkProp3D::ComputeMatrix() 0x7ffff6cc91ab
7 vtkOpenGLActor::GetKeyMatrices(vtkMatrix4x4 *&, vtkMatrix3x3 *&) 0x7ffff74240e0
8 vtkOpenGLPolyDataMapper::SetCameraShaderParameters(vtkOpenGLHelper&, vtkRenderer *, vtkActor *) 0x7ffff746a582
9 vtkOpenGLPolyDataMapper::UpdateShaders(vtkOpenGLHelper&, vtkRenderer *, vtkActor *) 0x7ffff747b0fe
10 vtkOpenGLPolyDataMapper::RenderPieceDraw(vtkRenderer *, vtkActor *) 0x7ffff746aa42
11 vtkOpenGLPolyDataMapper::RenderPiece(vtkRenderer *, vtkActor *) 0x7ffff747e254
12 vtkPolyDataMapper::Render(vtkRenderer *, vtkActor *) 0x7ffff6cc7d03
13 vtkActor::RenderOpaqueGeometry(vtkViewport *) 0x7ffff6c330b7
14 vtkRenderer::DeviceRenderOpaqueGeometry() 0x7ffff6cd553b
15 vtkOpenGLRenderer::DeviceRenderOpaqueGeometry() 0x7ffff74995c8
16 vtkOpenGLRenderer::UpdateGeometry() 0x7ffff7497778
17 vtkOpenGLRenderer::DeviceRender() 0x7ffff7496474
18 vtkRenderer::Render() 0x7ffff6cd8224
19 vtkRendererCollection::Render() 0x7ffff6cd4490
20 vtkRenderWindow::DoStereoRender() 0x7ffff6ce1215
21 vtkRenderWindow::Render() 0x7ffff6ce34d6
22 vtkGenericOpenGLRenderWindow::Render() 0x7ffff74213b1
23 vtkInternalOpenGLRenderWindow::InternalRender vtkInternalOpenGLRenderWindow.cpp 41 0x555555629f78
24 QVTKFramebufferObjectRenderer::render QVtkFramebufferObjectItem.cpp 51 0x555555629844
25 ?? 0x7ffff4efb55a
26 ?? 0x7ffff415f670
27 QQuickWindowPrivate::renderSceneGraph(QSize const&, QSize const&) 0x7ffff4de45e7
28 ?? 0x7ffff4d84b69
29 ?? 0x7ffff4d88fb7
30 ?? 0x7ffff3f3a14c
31 start_thread pthread_create.c 477 0x7ffff361d609
32 clone clone.S 95 0x7ffff3b67103

It looks like you are accessing VTK objects from some worker thread. If you don’t prevent simultaneous access to the same VTK object from multiple threads then your application is expected to crash. It may also be a problem if you are not careful about activating and using OpenGL contexts in each thread.

Thanks Andras, your hint was the correct one, we realized that in our new environment (ubuntu 20 + Qt5.15) we were accessing VTK objects from different threads at the same time (the main gui thread and the graph scene render thread). It looks like that in our previous environment (Ubuntu 16+Qt5.9) all that was happening in the same thread. So as a workaround for now we use QSG_RENDER_LOOP=basic, and no more crashes.
I found this doc particularly useful: