# VTK Chart Overlay Doesn't work with VTK 9

**URL:** https://discourse.vtk.org/t/vtk-chart-overlay-doesnt-work-with-vtk-9/3616
**Category:** Development
**Created:** [June 22, 2020, 5:42pm UTC](https://discourse.vtk.org/t/vtk-chart-overlay-doesnt-work-with-vtk-9/3616 "2020-06-22T17:42:31Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![Andrew](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andrew/32/3861_2.png) [@Andrew](https://discourse.vtk.org/u/Andrew)
#### Post date: [June 22, 2020, 5:42pm UTC](https://discourse.vtk.org/t/vtk-chart-overlay-doesnt-work-with-vtk-9/3616/1 "2020-06-22T17:42:31Z")

</div>

Hey everyone, I’m trying to overlay a chart on a 3d scene. This works in VTK versions \< 9. Additionally I found the chart overlay example online doesn’t work with VTK 9.

Example: https://lorensen.github.io/VTKExamples/site/Cxx/Plotting/ChartsOn3DScene/

Is this a bug? Is there any workaround? Here’s the call stack:

```
vtkRenderingContext2D-9.0.dll!vtkContextActor::RenderOverlay(vtkViewport * viewport) Line 230	C++
vtkRenderingOpenGL2-9.0.dll!vtkOpenGLRenderer::UpdateGeometry(vtkFrameBufferObjectBase * fbo) Line 406	C++
vtkRenderingOpenGL2-9.0.dll!vtkOpenGLRenderer::DeviceRender() Line 263	C++
vtkRenderingCore-9.0.dll!vtkRenderer::Render() Line 378	C++
vtkRenderingCore-9.0.dll!vtkRendererCollection::Render() Line 53	C++
vtkRenderingCore-9.0.dll!vtkRenderWindow::DoStereoRender() Line 340	C++
vtkRenderingCore-9.0.dll!vtkRenderWindow::Render() Line 299	C++
vtkRenderingOpenGL2-9.0.dll!vtkOpenGLRenderWindow::Render() Line 2042	C++
ChartsOn3DScene.exe!main(int __formal, char * *__ formal) Line 119	C++

```

In particular on ln230 of vtkContextActor.cxx it tries to access a NULL device from the context resulting in an access violation reading location thrown.

---

<div class="post-metadata">

### Author: ![Andrew](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andrew/32/3861_2.png) [@Andrew](https://discourse.vtk.org/u/Andrew)
#### Post date: [June 24, 2020, 1:19am UTC](https://discourse.vtk.org/t/vtk-chart-overlay-doesnt-work-with-vtk-9/3616/2 "2020-06-24T01:19:46Z")

</div>

This appears to already be fixed on master and only present on the VTK 9 release.

---

<div class="post-metadata">

### Author: ![codeling](https://discourse.vtk.org/user_avatar/discourse.vtk.org/codeling/32/3792_2.png) [@codeling](https://discourse.vtk.org/u/codeling)
#### Post date: [July 27, 2020, 8:09pm UTC](https://discourse.vtk.org/t/vtk-chart-overlay-doesnt-work-with-vtk-9/3616/3 "2020-07-27T20:09:40Z")

</div>

Do you know which change is fixing the problem you encountered? Should this fix be included in 9.0.1? We are getting similar problems, but they aren’t resolved with 9.0.1, so I’m wondering whether this is a different issue, or whether the fix just isn’t included in 9.0.1 yet…

---

<div class="post-metadata">

### Author: ![Andrew](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andrew/32/3861_2.png) [@Andrew](https://discourse.vtk.org/u/Andrew)
#### Post date: [July 27, 2020, 8:53pm UTC](https://discourse.vtk.org/t/vtk-chart-overlay-doesnt-work-with-vtk-9/3616/4 "2020-07-27T20:53:03Z")

</div>

Sadly I can’t quite remember what fixed it. It was a build change. The VTK examples cmake on the website was different that that of the VTK repository itself. One worked the other didn’t. I think I one was just missing some modules in its cmake script. I’d ensure your building and linking to RenderingContext2D, ViewsContext2D, RenderingContextOpenGL2. And calling autoinit in your cmake. I believe I had found the autoinit of these was missing and caused the opengl context to be null.

---

<div class="post-metadata">

### Author: ![codeling](https://discourse.vtk.org/user_avatar/discourse.vtk.org/codeling/32/3792_2.png) [@codeling](https://discourse.vtk.org/u/codeling)
#### Post date: [July 28, 2020, 5:43am UTC](https://discourse.vtk.org/t/vtk-chart-overlay-doesnt-work-with-vtk-9/3616/5 "2020-07-28T05:43:27Z")

</div>

> [@Andrew](#):
>
> RenderingContext2D, ViewsContext2D, RenderingContextOpenGL2

I suspected a missing module as well initially… I’ll try if adding one of those fixes it, thanks for the fast answer!

---

<div class="post-metadata">

### Author: ![codeling](https://discourse.vtk.org/user_avatar/discourse.vtk.org/codeling/32/3792_2.png) [@codeling](https://discourse.vtk.org/u/codeling)
#### Post date: [July 28, 2020, 8:50am UTC](https://discourse.vtk.org/t/vtk-chart-overlay-doesnt-work-with-vtk-9/3616/6 "2020-07-28T08:50:05Z")

</div>

Could not fix it that way yet - adding RenderingContext2D and ViewsContext2D does not help, and RenderingContextOpenGL2 doesn’t seem to exist in VTK \>= 9.0.0…

Is there an _easy_ way to figure out which library is missing if such a crash occurs? I find such errors quite hard to debug, especially if the required libraries change between versions…

---

<div class="post-metadata">

### Author: ![estan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/estan/32/460_2.png) [@estan](https://discourse.vtk.org/u/estan)
#### Post date: [July 28, 2020, 10:41am UTC](https://discourse.vtk.org/t/vtk-chart-overlay-doesnt-work-with-vtk-9/3616/7 "2020-07-28T10:41:26Z")

</div>

> Could not fix it that way yet - adding RenderingContext2D and ViewsContext2D does not help, and RenderingContextOpenGL2 doesn’t seem to exist in VTK \>= 9.0.0…

It does exist in VTK 9.0.0, but due to the build system changes in VTK 9.0.0 it’s not implicitly enabled the same way as it was in some circumstances with the earlier build system. For my build, I had to manually enable this module with

```
-DVTK_MODULE_ENABLE_VTK_RenderingContextOpenGL2=YES

```

See some of the hits here for people who ran into the same gotcha: [Search results for 'RenderingContextOpenGL2' - VTK](https://discourse.vtk.org/search?q=RenderingContextOpenGL2)

Hope that helps.

---

<div class="post-metadata">

### Author: ![codeling](https://discourse.vtk.org/user_avatar/discourse.vtk.org/codeling/32/3792_2.png) [@codeling](https://discourse.vtk.org/u/codeling)
#### Post date: [July 30, 2020, 1:39pm UTC](https://discourse.vtk.org/t/vtk-chart-overlay-doesnt-work-with-vtk-9/3616/8 "2020-07-30T13:39:26Z")

</div>

Thanks for the pointer - beating myself up now because I didn’t think of checking the available options earlier (I do have `VTK_MODULE_ENABLE_VTK_RenderingContextOpenGL2` as setting shown in cmake, it wasn’t enabled yet)! Unfortunately, this also didn’t help yet, our code still crashes at vtkContext2D::GetDevice returning a nullptr… so I guess I might miss yet another module?  
Here’s the list of VTK components which I currently pass into autoinit (several of course are probably only needed for unrelated purposes):  
`VTK::FiltersModeling;VTK::InteractionImage;VTK::InteractionWidgets;VTK::ImagingStatistics;VTK::IOGeometry;VTK::IOMovie;VTK::RenderingAnnotation;VTK::RenderingContextOpenGL2;VTK::RenderingImage;VTK::RenderingVolumeOpenGL2;VTK::RenderingQt;VTK::ViewsContext2D;VTK::ViewsInfovis;VTK::ChartsCore;VTK::CommonColor;VTK::CommonComputationalGeometry;VTK::GUISupportQt;VTK::FiltersExtraction;VTK::FiltersGeometry;VTK::FiltersHybrid;VTK::FiltersStatistics;VTK::ImagingHybrid;VTK::InfovisLayout;VTK::IOXML;VTK::RenderingContext2D;VTK::RenderingOpenVR;VTK::theora;VTK::ogg;VTK::IOOggTheora`

I’m not familiar with the internals of VTK’s module system, so in the following I’m probably missing loads of intricate stuff; I just can say that from a user’s perspective, I do find this behavior of having functionality that compiles fine, but then crashes at runtime quite annoying; my gut tells me there should be a better way - VTK telling you what modules to auto-configure (or even automatically doing that), or at least telling me on startup of the specific functionality, that currently no implementation of this functionality is available (and ideally the names of the modules which can provide it). I guess if this could be done _easily_, it would have been done already. I hope this could be done at some point in the future, I would find it extremely helpful!

Or is there at least a list of modules and for what they are required? I’ve skimmed [the VTK Module System](https://vtk.org/doc/nightly/html/md__home_kitware_dashboards_buildbot_vtk_nightly-master-ike-linux-shared-release_doc_nightly_osm749dd663df9981384f2598c108aac3b0.html#autoinit) description, but for me as a user I don’t see any actionable information in there regarding my issue - i.e. information on which modules I need to autoinit for specific functionality to work.

---

<div class="post-metadata">

### Author: ![Andrew](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andrew/32/3861_2.png) [@Andrew](https://discourse.vtk.org/u/Andrew)
#### Post date: [July 30, 2020, 5:48pm UTC](https://discourse.vtk.org/t/vtk-chart-overlay-doesnt-work-with-vtk-9/3616/9 "2020-07-30T17:48:15Z")

</div>

> [@codeling](#):
>
> VTK::FiltersModeling;VTK::InteractionImage;VTK::InteractionWidgets;VTK::ImagingStatistics;VTK::IOGeometry;VTK::IOMovie;VTK::RenderingAnnotation;VTK::RenderingContextOpenGL2;VTK::RenderingImage;VTK::RenderingVolumeOpenGL2;VTK::RenderingQt;VTK::ViewsContext2D;VTK::ViewsInfovis;VTK::ChartsCore;VTK::CommonColor;VTK::CommonComputationalGeometry;VTK::GUISupportQt;VTK::FiltersExtraction;VTK::FiltersGeometry;VTK::FiltersHybrid;VTK::FiltersStatistics;VTK::ImagingHybrid;VTK::InfovisLayout;VTK::IOXML;VTK::RenderingContext2D;VTK::RenderingOpenVR;VTK::theora;VTK::ogg;VTK::IOOggTheora

Here’s our current list in [Imstk](https://gitlab.kitware.com/iMSTK/iMSTK.git) which allows us to do chart overlays in VTK 9.

```
  -DVTK_MODULE_ENABLE_VTK_ChartsCore:STRING=YES
  -DVTK_MODULE_ENABLE_VTK_FiltersCore:STRING=YES
  -DVTK_MODULE_ENABLE_VTK_FiltersExtraction:STRING=YES
  -DVTK_MODULE_ENABLE_VTK_FiltersGeneral:STRING=YES
  -DVTK_MODULE_ENABLE_VTK_FiltersModeling:STRING=YES
  -DVTK_MODULE_ENABLE_VTK_ImagingGeneral:STRING=YES
  -DVTK_MODULE_ENABLE_VTK_ImagingStencil:STRING=YES
  -DVTK_MODULE_ENABLE_VTK_IOExport:STRING=YES
  -DVTK_MODULE_ENABLE_VTK_IOGeometry:STRING=YES
  -DVTK_MODULE_ENABLE_VTK_IOImport:STRING=YES
  -DVTK_MODULE_ENABLE_VTK_IOLegacy:STRING=YES
  -DVTK_MODULE_ENABLE_VTK_IOPLY:STRING=YES
  -DVTK_MODULE_ENABLE_VTK_IOParallel:STRING=YES
  -DVTK_MODULE_ENABLE_VTK_IOParallelXML:STRING=YES
  -DVTK_MODULE_ENABLE_VTK_IOXML:STRING=YES
  -DVTK_MODULE_ENABLE_VTK_InteractionStyle:STRING=YES
  -DVTK_MODULE_ENABLE_VTK_InteractionWidgets:STRING=YES
  -DVTK_MODULE_ENABLE_VTK_RenderingAnnotation:STRING=YES
  -DVTK_MODULE_ENABLE_VTK_RenderingContext2D:STRING=YES
  -DVTK_MODULE_ENABLE_VTK_RenderingContextOpenGL2:STRING=YES
  -DVTK_MODULE_ENABLE_VTK_RenderingOpenGL2:STRING=YES
  -DVTK_MODULE_ENABLE_VTK_RenderingOpenVR:STRING=${VTK_ENABLE_OPENVR}
  -DVTK_MODULE_ENABLE_VTK_RenderingVolumeOpenGL2:STRING=YES
  -DVTK_MODULE_ENABLE_VTK_ViewsContext2D:STRING=YES
  -DVTK_MODULE_ENABLE_VTK_glew:STRING=YES
  -DVTK_BUILD_EXAMPLES:STRING=DONT_WANT
  -DVTK_BUILD_TESTING:STRING=OFF
  -DVTK_GROUP_ENABLE_StandAlone:STRING=DONT_WANT
  -DVTK_GROUP_ENABLE_Rendering:STRING=DONT_WANT

```

And when autoinit is run on the project it produces these preprocessor definitions for my system.

> vtkRenderingContext2D\_AUTOINIT\_INCLUDE=“C:/Repos/iMSTKAW/buildWin64/Innerbuild/CMakeFiles/vtkModuleAutoInit\_f0a3767b8e2952ee742886044a92ae4c.h”  
> vtkRenderingCore\_AUTOINIT\_INCLUDE=“C:/Repos/iMSTKAW/buildWin64/Innerbuild/CMakeFiles/vtkModuleAutoInit\_f0a3767b8e2952ee742886044a92ae4c.h”  
> vtkRenderingVolume\_AUTOINIT\_INCLUDE=“C:/Repos/iMSTKAW/buildWin64/Innerbuild/CMakeFiles/vtkModuleAutoInit\_f0a3767b8e2952ee742886044a92ae4c.h”

Additionally you will find the example within the VTK repo directory works but the example on the website does not.

---

<div class="post-metadata">

### Author: ![codeling](https://discourse.vtk.org/user_avatar/discourse.vtk.org/codeling/32/3792_2.png) [@codeling](https://discourse.vtk.org/u/codeling)
#### Post date: [July 31, 2020, 6:54am UTC](https://discourse.vtk.org/t/vtk-chart-overlay-doesnt-work-with-vtk-9/3616/10 "2020-07-31T06:54:42Z")

</div>

Finally found the problem: I need to do the `vtk_module_autoinit` directly on the library using the chart overlay.

Previously, we had only done the `vtk_module_autoinit` on our core library (a .dll /.so) which was used from all our other libraries and which exports VTK libraries by using `PUBLIC` in the `target_link_library` call with VTK libraries…

---

<div class="post-metadata">

### Author: ![estan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/estan/32/460_2.png) [@estan](https://discourse.vtk.org/u/estan)
#### Post date: [July 31, 2020, 7:13am UTC](https://discourse.vtk.org/t/vtk-chart-overlay-doesnt-work-with-vtk-9/3616/11 "2020-07-31T07:13:00Z")

</div>

@codeling That makes sense. Glad you found the problem.

BTW I agree that it would be good with some kind of warning/error mechanism for when you enable some piece of functionality (e.g. `RenderingContext2D`), but there’s no implementation module for it (e.g. `RenderingContextOpenGL2`) enabled, since that’s sort of a non-sensical config.

---

<div class="post-metadata">

### Author: ![estan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/estan/32/460_2.png) [@estan](https://discourse.vtk.org/u/estan)
#### Post date: [July 31, 2020, 7:15am UTC](https://discourse.vtk.org/t/vtk-chart-overlay-doesnt-work-with-vtk-9/3616/12 "2020-07-31T07:15:01Z")

</div>

> [@estan](#):
>
> BTW I agree that it would be good with some kind of warning/error mechanism for when you enable some piece of functionality (e.g. `RenderingContext2D` ), but there’s no implementation module for it (e.g. `RenderingContextOpenGL2` ) enabled, since that’s sort of a non-sensical config.

…though I guess in theory you could provide your own implementation, but I’m not sure that is so common.

---

<div class="post-metadata">

### Author: ![codeling](https://discourse.vtk.org/user_avatar/discourse.vtk.org/codeling/32/3792_2.png) [@codeling](https://discourse.vtk.org/u/codeling)
#### Post date: [August 4, 2020, 11:21am UTC](https://discourse.vtk.org/t/vtk-chart-overlay-doesnt-work-with-vtk-9/3616/13 "2020-08-04T11:21:44Z")

</div>

> [@codeling](#):
>
> Previously, we had only done the `vtk_module_autoinit` on our core library (a .dll /.so) which was used from all our other libraries and which exports VTK libraries by using `PUBLIC` in the `target_link_library` call with VTK libraries…

On reflecting more on this more, I guess this is because the `INCLUDE(${VTK_USE_FILE})` we used in VTK versions \< 9 probably did that automatically on a global level.

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [January 11, 2021, 10:40am UTC](https://discourse.vtk.org/t/vtk-chart-overlay-doesnt-work-with-vtk-9/3616/14 "2021-01-11T10:40:55Z")

</div>

A bit late to the party, but [FindNeededModules.py](https://gitlab.kitware.com/vtk/vtk/-/blob/master/Utilities/Maintenance/FindNeededModules.py) usually works quite well in finding what modules your code needs. It is not guarenteed to find all needed modules but it does a pretty good job. I didn’t notice any issues with [ChartsOn3DScene](https://kitware.github.io/vtk-examples/site/Cxx/Plotting/ChartsOn3DScene/). Building and testing seems to work Ok.

---

<div class="post-metadata">

### Author: ![codeling](https://discourse.vtk.org/user_avatar/discourse.vtk.org/codeling/32/3792_2.png) [@codeling](https://discourse.vtk.org/u/codeling)
#### Post date: [January 11, 2021, 5:35pm UTC](https://discourse.vtk.org/t/vtk-chart-overlay-doesnt-work-with-vtk-9/3616/15 "2021-01-11T17:35:26Z")

</div>

Thanks for the hint, that sounds like something I should try!
