# segfault in vtkOpenGLRenderWindow::OpenGLInitState()

**URL:** https://discourse.vtk.org/t/segfault-in-vtkopenglrenderwindow-openglinitstate/14366
**Category:** Support
**Created:** [August 7, 2024, 9:04pm UTC](https://discourse.vtk.org/t/segfault-in-vtkopenglrenderwindow-openglinitstate/14366 "2024-08-07T21:04:19Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Tomasso](https://discourse.vtk.org/user_avatar/discourse.vtk.org/tomasso/32/5786_2.png) [@Tomasso](https://discourse.vtk.org/u/Tomasso)
#### Post date: [August 7, 2024, 9:04pm UTC](https://discourse.vtk.org/t/segfault-in-vtkopenglrenderwindow-openglinitstate/14366/1 "2024-08-07T21:04:20Z")

</div>

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

```auto
  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!

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [August 7, 2024, 9:06pm UTC](https://discourse.vtk.org/t/segfault-in-vtkopenglrenderwindow-openglinitstate/14366/2 "2024-08-07T21:06:15Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Tomasso](https://discourse.vtk.org/user_avatar/discourse.vtk.org/tomasso/32/5786_2.png) [@Tomasso](https://discourse.vtk.org/u/Tomasso)
#### Post date: [August 7, 2024, 9:11pm UTC](https://discourse.vtk.org/t/segfault-in-vtkopenglrenderwindow-openglinitstate/14366/3 "2024-08-07T21:11:34Z")

</div>

Thanks. Yes, renderWindow\_-\>vtkOpenGLRenderWindow::OpenGLInit() also segfaults.

---

<div class="post-metadata">

### Author: ![Jens\_Munk\_Hansen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jens_munk_hansen/32/1215_2.png) [@Jens\_Munk\_Hansen](https://discourse.vtk.org/u/Jens_Munk_Hansen)
#### Post date: [August 7, 2024, 9:16pm UTC](https://discourse.vtk.org/t/segfault-in-vtkopenglrenderwindow-openglinitstate/14366/4 "2024-08-07T21:16:40Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Tomasso](https://discourse.vtk.org/user_avatar/discourse.vtk.org/tomasso/32/5786_2.png) [@Tomasso](https://discourse.vtk.org/u/Tomasso)
#### Post date: [August 7, 2024, 9:20pm UTC](https://discourse.vtk.org/t/segfault-in-vtkopenglrenderwindow-openglinitstate/14366/5 "2024-08-07T21:20:42Z")

</div>

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

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

```

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [August 7, 2024, 9:28pm UTC](https://discourse.vtk.org/t/segfault-in-vtkopenglrenderwindow-openglinitstate/14366/6 "2024-08-07T21:28:46Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Tomasso](https://discourse.vtk.org/user_avatar/discourse.vtk.org/tomasso/32/5786_2.png) [@Tomasso](https://discourse.vtk.org/u/Tomasso)
#### Post date: [August 7, 2024, 9:32pm UTC](https://discourse.vtk.org/t/segfault-in-vtkopenglrenderwindow-openglinitstate/14366/7 "2024-08-07T21:32:35Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [August 7, 2024, 9:45pm UTC](https://discourse.vtk.org/t/segfault-in-vtkopenglrenderwindow-openglinitstate/14366/8 "2024-08-07T21:45:23Z")

</div>

The code from [https://gitlab.kitware.com/vtk/vtk/-/blob/master/GUISupport/QtQuick/QQuickVTKRenderWindow.cxx#L91](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

---

<div class="post-metadata">

### Author: ![Tomasso](https://discourse.vtk.org/user_avatar/discourse.vtk.org/tomasso/32/5786_2.png) [@Tomasso](https://discourse.vtk.org/u/Tomasso)
#### Post date: [August 7, 2024, 10:09pm UTC](https://discourse.vtk.org/t/segfault-in-vtkopenglrenderwindow-openglinitstate/14366/9 "2024-08-07T22:09:06Z")

</div>

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

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [August 7, 2024, 10:46pm UTC](https://discourse.vtk.org/t/segfault-in-vtkopenglrenderwindow-openglinitstate/14366/10 "2024-08-07T22:46:26Z")

</div>

I couldn’t find QtQuick applications on the VTK examples website. VTK’s QtQuick [unit tests](https://gitlab.kitware.com/vtk/vtk/-/tree/master/GUISupport/QtQuick/Testing/Cxx?ref_type=heads) should help.

---

<div class="post-metadata">

### Author: ![Tomasso](https://discourse.vtk.org/user_avatar/discourse.vtk.org/tomasso/32/5786_2.png) [@Tomasso](https://discourse.vtk.org/u/Tomasso)
#### Post date: [August 7, 2024, 11:02pm UTC](https://discourse.vtk.org/t/segfault-in-vtkopenglrenderwindow-openglinitstate/14366/11 "2024-08-07T23:02:49Z")

</div>

Great, I will take a look. Thanks!

---

<div class="post-metadata">

### Author: ![Tomasso](https://discourse.vtk.org/user_avatar/discourse.vtk.org/tomasso/32/5786_2.png) [@Tomasso](https://discourse.vtk.org/u/Tomasso)
#### Post date: [August 9, 2024, 1:52am UTC](https://discourse.vtk.org/t/segfault-in-vtkopenglrenderwindow-openglinitstate/14366/13 "2024-08-09T01:52:25Z")

</div>

Gosh I cannot for the life of me figure out how to use QQuickVTKItem from the unit tests.  
[Documentation for QQuickVTKRenderItem](https://vtk.org/doc/nightly/html/classQQuickVTKRenderItem.html#details) 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](https://vtk.org/doc/nightly/html//classQQuickVTKItem.html#details) has no such example - and I’m afraid I’m just not grokking the unit tests. Any clues appreciated!  
Thanks!

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [August 9, 2024, 1:48pm UTC](https://discourse.vtk.org/t/segfault-in-vtkopenglrenderwindow-openglinitstate/14366/14 "2024-08-09T13:48:33Z")

</div>

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](https://gitlab.kitware.com/vtk/vtk/-/blob/master/GUISupport/QtQuick/Testing/Cxx/TestQQuickVTKItem_2.cxx)?

---

<div class="post-metadata">

### Author: ![Tomasso](https://discourse.vtk.org/user_avatar/discourse.vtk.org/tomasso/32/5786_2.png) [@Tomasso](https://discourse.vtk.org/u/Tomasso)
#### Post date: [August 12, 2024, 8:28pm UTC](https://discourse.vtk.org/t/segfault-in-vtkopenglrenderwindow-openglinitstate/14366/15 "2024-08-12T20:28:23Z")

</div>

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

```auto
$ 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!

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [August 12, 2024, 8:39pm UTC](https://discourse.vtk.org/t/segfault-in-vtkopenglrenderwindow-openglinitstate/14366/16 "2024-08-12T20:39:51Z")

</div>

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

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

---

<div class="post-metadata">

### Author: ![Tomasso](https://discourse.vtk.org/user_avatar/discourse.vtk.org/tomasso/32/5786_2.png) [@Tomasso](https://discourse.vtk.org/u/Tomasso)
#### Post date: [August 12, 2024, 8:49pm UTC](https://discourse.vtk.org/t/segfault-in-vtkopenglrenderwindow-openglinitstate/14366/17 "2024-08-12T20:49:29Z")

</div>

Here it is:

```auto
% 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

```

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [August 12, 2024, 8:54pm UTC](https://discourse.vtk.org/t/segfault-in-vtkopenglrenderwindow-openglinitstate/14366/18 "2024-08-12T20:54:41Z")

</div>

> [@Tomasso](#):
>
> `ERR| vtkGenericOpenGLRenderWindow (0x55d34121fff0): GLEW could not be initialized: Unknown error`

Check if you’ve all the dependencies on ubuntu or their equivalent in your distro [docs.vtk.org#creating-the-build-environment](https://docs.vtk.org/en/latest/build_instructions/index.html#creating-the-build-environment)

---

<div class="post-metadata">

### Author: ![Tomasso](https://discourse.vtk.org/user_avatar/discourse.vtk.org/tomasso/32/5786_2.png) [@Tomasso](https://discourse.vtk.org/u/Tomasso)
#### Post date: [August 12, 2024, 9:26pm UTC](https://discourse.vtk.org/t/segfault-in-vtkopenglrenderwindow-openglinitstate/14366/19 "2024-08-12T21:26:19Z")

</div>

Apparently [this error is generated by a known Wayland problem](https://gitlab.kitware.com/vtk/vtk/-/issues/19357). 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!

```auto
$ 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!

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [August 12, 2024, 9:31pm UTC](https://discourse.vtk.org/t/segfault-in-vtkopenglrenderwindow-openglinitstate/14366/20 "2024-08-12T21:31:52Z")

</div>

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`

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [August 12, 2024, 9:33pm UTC](https://discourse.vtk.org/t/segfault-in-vtkopenglrenderwindow-openglinitstate/14366/21 "2024-08-12T21:33:58Z")

</div>

> [@Tomasso](#):
>
> But I do not see a graphical output from the test, in this case a cone. Shouldn’t I?

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.

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

```

[Next page](https://discourse.vtk.org/t/segfault-in-vtkopenglrenderwindow-openglinitstate/14366.md?page=2)
