segfault in vtkOpenGLRenderWindow::OpenGLInitState()

I’m running VTK-9.3.1 on ubuntu-22.04
My application instantiates a vtkGenericOpenGLRenderWindow and invokes vtkOpenGLRenderWindow::OpenGLInitState():

  renderWindow_ =
    vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();

  renderWindow_->OpenGLInitState();

But renderWindow_->OpenGLInitState() segfaults somewhere in this call stack at Rendering/OpenGL2/vtkOpenGLRenderWindow.cxx:631

this->GetState()->Initialize(this)

What’s the proper way to initialize vtkGenericOpenGLRenderWindow?
Thanks!

Segfaults most likely because the opengl function pointers are all null. Have you tried calling renderWindow_->vtkOpenGLRenderWindow::OpenGLInit() instead?

1 Like

Thanks. Yes, renderWindow_->vtkOpenGLRenderWindow::OpenGLInit() also segfaults.

Have you checked that OpenGL is working on your platform. glxinfo | grep "OpenGL version"

Yes, other OpenGL apps are working on my platform. And

glxinfo | grep "OpenGL version"
OpenGL version string: 4.6 (Compatibility Profile) Mesa 23.0.4-0ubuntu1~22.04.1

Do you really need to use a vtkGenericOpenGLRenderWindow? That class is generally used by applications that have already setup a win32/x/cocoa window. Did you do that?

My app uses vtk to render a surface within Qt, in a QQuickItem. The app was written several years ago, worked with Qt5 and VTK-9.2 using vtkGenericOpenGLRenderWindow, I assume because Qt sets up OpenGL beforehand… Now segfaults with Qt6 and VTK-9.3.

The code from https://gitlab.kitware.com/vtk/vtk/-/blob/master/GUISupport/QtQuick/QQuickVTKRenderWindow.cxx#L91 can guide you on how to do it correctly. Something may have changed since 9.2

1 Like

Thanks for that link!
Do you know of an example that uses QQuickVTKItem and QQuickVTKRenderer?

I couldn’t find QtQuick applications on the VTK examples website. VTK’s QtQuick unit tests should help.

1 Like

Great, I will take a look. Thanks!

Gosh I cannot for the life of me figure out how to use QQuickVTKItem from the unit tests.
Documentation for QQuickVTKRenderItem has a nice clear example - yet when I try to build that simple app the compiler gives warning: ‘QQuickVTKRenderWindow’ is deprecated: Use QQuickVTKItem instead
But documentation for QQuickVTKItem has no such example - and I’m afraid I’m just not grokking the unit tests. Any clues appreciated!
Thanks!

You can build the unit tests with the cmake flag -DVTK_BUILD_TESTING=WANT and run them from the build directory with ctest. You can run ctest -N -VV to actually see the full path to test executables and arguments passed to them. ctest -R NameOfTest is another way to run a specific unit test. Have you seen https://gitlab.kitware.com/vtk/vtk/-/blob/master/GUISupport/QtQuick/Testing/Cxx/TestQQuickVTKItem_2.cxx?

2 Likes

Thanks! I built the VTK-9.3.1 tests, but when I try to run TestQQuickVTKItem_1 I get an error:

$ ctest -R VTK::GUISupportQtQuickCxx-TestQQuickVTKItem_1
Test project /home/oreilly/VTK-9.3.1/build
    Start 502: VTK::GUISupportQtQuickCxx-TestQQuickVTKItem_1
1/1 Test #502: VTK::GUISupportQtQuickCxx-TestQQuickVTKItem_1 ...***Failed  Error regular expression found in output. Regex=[ERR\|]  4.25 sec

I get similar errors for TestQQuickVTKItem_2 and TestQQuickVTKItem_3.
I’m a ctest newbie - am I making an obvious error?
Thanks!

Can you increase the verbosity by running it with -VV?

Try ctest -R VTK::GUISupportQtQuickCxx-TestQQuickVTKItem_1 -VV

Here it is:

% ctest -R VTK::GUISupportQtQuickCxx-TestQQuickVTKItem_1 -VV
UpdateCTestConfiguration  from :/home/oreilly/VTK-9.3.1/build/DartConfiguration.
tcl
Parse Config file:/home/oreilly/VTK-9.3.1/build/DartConfiguration.tcl
 Add coverage exclude regular expressions.
 Add coverage exclude: vtk[^\.]+(Java|Python).cxx
 Add coverage exclude: .*Testing.Cxx.*cxx
 Add coverage exclude: .*Testing.Cxx.*h
 Add coverage exclude: .*moc_.*cxx
 Add coverage exclude: .*/Utilities/.*
 Add coverage exclude: .*/ThirdParty/.*
UpdateCTestConfiguration  from :/home/oreilly/VTK-9.3.1/build/DartConfiguration.tcl
Parse Config file:/home/oreilly/VTK-9.3.1/build/DartConfiguration.tcl
Test project /home/oreilly/VTK-9.3.1/build
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 502
    Start 502: VTK::GUISupportQtQuickCxx-TestQQuickVTKItem_1

502: Test command: /home/oreilly/VTK-9.3.1/build/bin/vtkGUISupportQtQuickCxxTests "TestQQuickVTKItem_1" "-D" "/home/oreilly/VTK-9.3.1/build/ExternalData/Testing" "-T" "/home/oreilly/VTK-9.3.1/build/Testing/Temporary" "-V" "/home/oreilly/VTK-9.3.1/build/ExternalData/GUISupport/QtQuick/Testing/Data/Baseline/TestQQuickVTKItem_1.png"
502: Working Directory: /home/oreilly/VTK-9.3.1/build/GUISupport/QtQuick/Testing/Cxx
502: Test timeout computed to be: 1500
502: CTEST_FULL_OUTPUT (Avoid ctest truncation of output)
502: ESC[0mESC[31m(   1.898s) [main thread     ]vtkOpenGLRenderWindow.c:701    ERR| vtkGenericOpenGLRenderWindow (0x55d34121fff0): GLEW could not be initialized: Unknown errorESC[0m
502: ESC[0mESC[31m(   1.902s) [main thread     ]vtkOpenGLRenderWindow.c:701    ERR| vtkGenericOpenGLRenderWindow (0x55d34121fff0): GLEW could not be initialized: Unknown errorESC[0m
502: <DartMeasurement name="ImageError" type="numeric/double">0</DartMeasurement><DartMeasurement name="BaselineImage" type="text/string">Standard</DartMeasurement>
1/1 Test #502: VTK::GUISupportQtQuickCxx-TestQQuickVTKItem_1 ...***Failed  Error regular expression found in output. Regex=[ERR\|]  3.07 sec

0% tests passed, 1 tests failed out of 1

Label Time Summary:
VTK::GUISupportQtQuick    =   3.07 sec*proc (1 test)
Total Test time (real) =   3.23 sec

The following tests FAILED:
        502 - VTK::GUISupportQtQuickCxx-TestQQuickVTKItem_1 (Failed)
Errors while running CTest
Output from these tests are in: /home/oreilly/VTK-9.3.1/build/Testing/Temporary/LastTest.log

Check if you’ve all the dependencies on ubuntu or their equivalent in your distro docs.vtk.org#creating-the-build-environment

Apparently this error is generated by a known Wayland problem. Does this mean that QQuickVTKItem and related will not work on ubuntu 22.04 running Wayland for the time being?

I’ve disabled Wayland - running x11 - and now the unit test passes - Hurray!

$ ctest -R VTK::GUISupportQtQuickCxx-TestQQuickVTKItem_1
Test project /home/oreilly/VTK-9.3.1/build
    Start 502: VTK::GUISupportQtQuickCxx-TestQQuickVTKItem_1
1/1 Test #502: VTK::GUISupportQtQuickCxx-TestQQuickVTKItem_1 ...   Passed    1.35 sec

100% tests passed, 0 tests failed out of 1

Label Time Summary:
VTK::GUISupportQtQuick    =   1.35 sec*proc (1 test)
vtkGUISupportQtQuick      =   1.35 sec*proc (1 test)

But I do not see a graphical output from the test, in this case a cone. Shouldn’t I?

Thanks!

Ah, if you don’t want to run on X11, it might work with EGL. For the moment, you may turn off X in VTK and turn on EGL.

cmake -DVTK_USE_X=OFF -DVTK_OPENGL_HAS_EGL=ON

The test exits immediately, so you might not see anything. Instead, you can run the unit test interactively with the “-I” flag. This flag is parsed by the C++ test, it is not a ctest option.

/home/oreilly/VTK-9.3.1/build/bin/vtkGUISupportQtQuickCxxTests "TestQQuickVTKItem_1" "-I"