# vtkGenericOpenGLRenderWindow vtkOrientationMarkerWidget crash

**URL:** https://discourse.vtk.org/t/vtkgenericopenglrenderwindow-vtkorientationmarkerwidget-crash/12646
**Category:** Development
**Created:** [November 8, 2023, 1:59pm UTC](https://discourse.vtk.org/t/vtkgenericopenglrenderwindow-vtkorientationmarkerwidget-crash/12646 "2023-11-08T13:59:57Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![xjjgjmeng](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/x/2acd7d/32.png) [@xjjgjmeng](https://discourse.vtk.org/u/xjjgjmeng)
#### Post date: [November 8, 2023, 1:59pm UTC](https://discourse.vtk.org/t/vtkgenericopenglrenderwindow-vtkorientationmarkerwidget-crash/12646/1 "2023-11-08T13:59:57Z")

</div>

I ran the example of the file

> [vtk-examples/src/Cxx/Widgets/OrientationMarkerWidget.cxx at master · Kitware/vtk-examples · GitHub](https://github.com/Kitware/vtk-examples/blob/master/src/Cxx/Widgets/OrientationMarkerWidget.cxx)

and the program ran very well, but I just changed **vtkRenderWindow** to **vtkGenericOpenGLRenderWindow** Then it crashed (vtk v9.2.6)(vs2019), the screenshot of the crash is as follows:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/2/22ecfa3acfffde52e25b1103e5e41b0ece0070d7.png)

Below is my modified code：

```auto
#include <vtkActor.h>
#include <vtkAnnotatedCubeActor.h>
#include <vtkCamera.h>
#include <vtkCubeSource.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkOrientationMarkerWidget.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkGenericOpenGLRenderWindow.h>

int main(int argc, char* argv[])
{
  vtkNew<vtkNamedColors> colors;

  // create a rendering window and renderer;
  vtkNew<vtkRenderer> ren;
  //vtkNew<vtkRenderWindow> renWin;
  vtkNew<vtkGenericOpenGLRenderWindow> renWin;
  renWin->AddRenderer(ren);
  renWin->SetWindowName("OrientationMarkerWidget");

  // create a renderwindowinteractor;
  vtkNew<vtkRenderWindowInteractor> iren;
  iren->SetRenderWindow(renWin);

  vtkNew<vtkCubeSource> cube;
  cube->SetXLength(200);
  cube->SetYLength(200);
  cube->SetZLength(200);
  cube->Update();
  vtkNew<vtkPolyDataMapper> cm;
  cm->SetInputConnection(cube->GetOutputPort());
  vtkNew<vtkActor> ca;
  ca->SetMapper(cm);
  ca->GetProperty()->SetColor(colors->GetColor3d("BurlyWood").GetData());
  ca->GetProperty()->EdgeVisibilityOn();
  ca->GetProperty()->SetEdgeColor(colors->GetColor3d("Red").GetData());

  // assign actor to the renderer;
  ren->AddActor(ca);
  ren->SetBackground(colors->GetColor3d("CornflowerBlue").GetData());

  vtkNew<vtkAnnotatedCubeActor> axesActor;
  axesActor->SetXPlusFaceText("L");
  axesActor->SetXMinusFaceText("R");
  axesActor->SetYMinusFaceText("I");
  axesActor->SetYPlusFaceText("S");
  axesActor->SetZMinusFaceText("P");
  axesActor->SetZPlusFaceText("A");
  axesActor->GetTextEdgesProperty()->SetColor(
      colors->GetColor3d("Yellow").GetData());
  axesActor->GetTextEdgesProperty()->SetLineWidth(2);
  axesActor->GetCubeProperty()->SetColor(colors->GetColor3d("Blue").GetData());
  vtkNew<vtkOrientationMarkerWidget> axes;
  axes->SetOrientationMarker(axesActor);
  axes->SetInteractor(iren);
  axes->EnabledOn();
  axes->InteractiveOn();
  ren->ResetCamera();

  // enable user interface interactor;
  iren->Initialize();
  renWin->Render();
  ren->GetActiveCamera()->Azimuth(45);
  ren->GetActiveCamera()->Elevation(30);
  renWin->Render();
  iren->Start();

  return EXIT_SUCCESS;
}

```

How to solve this problem? (Only **vtkGenericOpenGLRenderWindow** can be used in my code)

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [November 17, 2023, 4:05am UTC](https://discourse.vtk.org/t/vtkgenericopenglrenderwindow-vtkorientationmarkerwidget-crash/12646/2 "2023-11-17T04:05:40Z")

</div>

It looks like something is wrong with the OpenGL context. Does this work if you use the `vtk` Python wheel to do the same calls from a Python script doing the same setup?

---

<div class="post-metadata">

### Author: ![xjjgjmeng](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/x/2acd7d/32.png) [@xjjgjmeng](https://discourse.vtk.org/u/xjjgjmeng)
#### Post date: [November 17, 2023, 11:35am UTC](https://discourse.vtk.org/t/vtkgenericopenglrenderwindow-vtkorientationmarkerwidget-crash/12646/3 "2023-11-17T11:35:36Z")

</div>

I have this problem on both my own computer and my company’s computer

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [November 17, 2023, 12:14pm UTC](https://discourse.vtk.org/t/vtkgenericopenglrenderwindow-vtkorientationmarkerwidget-crash/12646/4 "2023-11-17T12:14:09Z")

</div>

@mwestphal Ideas?

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [November 17, 2023, 1:48pm UTC](https://discourse.vtk.org/t/vtkgenericopenglrenderwindow-vtkorientationmarkerwidget-crash/12646/5 "2023-11-17T13:48:15Z")

</div>

AFAIK the vtkGenericOpenGLRenderWindow cannot be used on its own. You can’t just swap a platform specific render window with one that does not create a OpenGL context.

vtkGenericOpenGLRenderWindow is intended to be used inside Qt or another framework.

---

<div class="post-metadata">

### Author: ![xjjgjmeng](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/x/2acd7d/32.png) [@xjjgjmeng](https://discourse.vtk.org/u/xjjgjmeng)
#### Post date: [November 18, 2023, 1:39pm UTC](https://discourse.vtk.org/t/vtkgenericopenglrenderwindow-vtkorientationmarkerwidget-crash/12646/6 "2023-11-18T13:39:27Z")

</div>

The [imgui-vtk](https://github.com/trlsmax/imgui-vtk) library seems to only use vtkGenericOpenGLRenderWindow, but does not use Qt or other frameworks.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [November 18, 2023, 1:42pm UTC](https://discourse.vtk.org/t/vtkgenericopenglrenderwindow-vtkorientationmarkerwidget-crash/12646/7 "2023-11-18T13:42:11Z")

</div>

There’s probably an object factory mechanism going on; are you using CMake to build your example? Or doing autoinit manually if not?

---

<div class="post-metadata">

### Author: ![xjjgjmeng](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/x/2acd7d/32.png) [@xjjgjmeng](https://discourse.vtk.org/u/xjjgjmeng)
#### Post date: [November 18, 2023, 2:28pm UTC](https://discourse.vtk.org/t/vtkgenericopenglrenderwindow-vtkorientationmarkerwidget-crash/12646/8 "2023-11-18T14:28:12Z")

</div>

Yes, I use cmake. I just cloned the code [vtk-examples](https://github.com/Kitware/vtk-examples/tree/master) and then cmake. I just changed the vtkRenderWindow in the file [OrientationMarkerWidget.cxx](https://github.com/Kitware/vtk-examples/blob/master/src/Cxx/Widgets/OrientationMarkerWidget.cxx) to vtkGenericOpenGLRenderWindow and it crashed (vtk v9.2.6)(vs2019). I think you should be able to reproduce this problem.

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [November 20, 2023, 3:13am UTC](https://discourse.vtk.org/t/vtkgenericopenglrenderwindow-vtkorientationmarkerwidget-crash/12646/9 "2023-11-20T03:13:24Z")

</div>

If you look at the “main.cpp” in the imgui-vtk library that you linked, you can see that it uses glfw to create a window with an OpenGL context:

```c++
// Create window with graphics context
  GLFWwindow* window = glfwCreateWindow(1280, 720, "Dear ImGui VTKViewer Example", NULL, NULL);

```

This is what Mathieu was referring to. The vtkGenericOpenGLRenderWindow needs something else to create the window and the OpenGL context. Otherwise, it will crash whenever you try to use it.

---

<div class="post-metadata">

### Author: ![xjjgjmeng](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/x/2acd7d/32.png) [@xjjgjmeng](https://discourse.vtk.org/u/xjjgjmeng)
#### Post date: [November 20, 2023, 5:07am UTC](https://discourse.vtk.org/t/vtkgenericopenglrenderwindow-vtkorientationmarkerwidget-crash/12646/10 "2023-11-20T05:07:15Z")

</div>

Thank you. It should be because vtkGenericOpenGLRenderWindow cannot be used alone.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [November 20, 2023, 7:06am UTC](https://discourse.vtk.org/t/vtkgenericopenglrenderwindow-vtkorientationmarkerwidget-crash/12646/11 "2023-11-20T07:06:38Z")

</div>

> [@xjjgjmeng](#):
>
> It should be because vtkGenericOpenGLRenderWindow cannot be used alone.

This class is not intended to be used alone, you can read its documentation:  
[https://vtk.org/doc/nightly/html/classvtkGenericOpenGLRenderWindow.html#details](https://vtk.org/doc/nightly/html/classvtkGenericOpenGLRenderWindow.html#details)

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

You **must** provide an opengl context.

But if you do not want to create the opengl context yourself, just use the platform specific window instead.

---

<div class="post-metadata">

### Author: ![xjjgjmeng](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/x/2acd7d/32.png) [@xjjgjmeng](https://discourse.vtk.org/u/xjjgjmeng)
#### Post date: [November 20, 2023, 8:11am UTC](https://discourse.vtk.org/t/vtkgenericopenglrenderwindow-vtkorientationmarkerwidget-crash/12646/12 "2023-11-20T08:11:45Z")

</div>

So, vtkRenderWindow creates an OpenGL context?

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [November 20, 2023, 8:59am UTC](https://discourse.vtk.org/t/vtkgenericopenglrenderwindow-vtkorientationmarkerwidget-crash/12646/13 "2023-11-20T08:59:43Z")

</div>

> [@xjjgjmeng](#):
>
> vtkRenderWindow creates an OpenGL context?

No, creating an openGL context is very different on each platform, that is why we have platform specific render window.

Just use the platform specific render window.

---

<div class="post-metadata">

### Author: ![xjjgjmeng](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/x/2acd7d/32.png) [@xjjgjmeng](https://discourse.vtk.org/u/xjjgjmeng)
#### Post date: [November 20, 2023, 9:22am UTC](https://discourse.vtk.org/t/vtkgenericopenglrenderwindow-vtkorientationmarkerwidget-crash/12646/14 "2023-11-20T09:22:53Z")

</div>

> [@xjjgjmeng](#):
>
> vtkRenderWindow

Can I think so: vtkRenderWindow is common to all platforms, and an OpenGL context will be created internally?

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [November 20, 2023, 9:28am UTC](https://discourse.vtk.org/t/vtkgenericopenglrenderwindow-vtkorientationmarkerwidget-crash/12646/15 "2023-11-20T09:28:46Z")

</div>

This is what happens when you use the factories. The plaform specific version of the vtkRenderWindow will be created for you.

---

<div class="post-metadata">

### Author: ![xjjgjmeng](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/x/2acd7d/32.png) [@xjjgjmeng](https://discourse.vtk.org/u/xjjgjmeng)
#### Post date: [November 20, 2023, 9:52am UTC](https://discourse.vtk.org/t/vtkgenericopenglrenderwindow-vtkorientationmarkerwidget-crash/12646/16 "2023-11-20T09:52:12Z")

</div>

I understand, thank you
