# How to debug this error when program is running?

**URL:** https://discourse.vtk.org/t/how-to-debug-this-error-when-program-is-running/12488
**Category:** Development
**Tags:** code
**Created:** [October 15, 2023, 12:36pm UTC](https://discourse.vtk.org/t/how-to-debug-this-error-when-program-is-running/12488 "2023-10-15T12:36:16Z")
**Posts on this page:** 17
**Page:** 2

<div class="post-metadata">

### Author: ![Dylan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dylan/32/7822_2.png) [@Dylan](https://discourse.vtk.org/u/Dylan)
#### Post date: [October 26, 2023, 2:24pm UTC](https://discourse.vtk.org/t/how-to-debug-this-error-when-program-is-running/12488/22 "2023-10-26T14:24:07Z")

</div>

yeah, You are very right, PC.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [October 26, 2023, 2:28pm UTC](https://discourse.vtk.org/t/how-to-debug-this-error-when-program-is-running/12488/23 "2023-10-26T14:28:05Z")

</div>

Listing here the headers that are being included in the source files may give us a hint of which GUI API is being used.

---

<div class="post-metadata">

### Author: ![Dylan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dylan/32/7822_2.png) [@Dylan](https://discourse.vtk.org/u/Dylan)
#### Post date: [October 26, 2023, 2:31pm UTC](https://discourse.vtk.org/t/how-to-debug-this-error-when-program-is-running/12488/24 "2023-10-26T14:31:54Z")

</div>

it is all about vtk:

```auto
#include <cstring>
#include <vector>
#include <vtkSTLReader.h>
#include <vtkMarchingCubes.h>
#include <vtkGlyph3D.h>
#include <vtkFixedPointVolumeRayCastMapper.h>
#include <vtkColorTransferFunction.h>
#include <vtkPiecewiseFunction.h>
#include <vtkVolumeProperty.h>
#include <vtkVolume.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkImageMapToColors.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkCutter.h>
#include <vtkPlane.h>
#include <vtkImageActor.h>
#include <vtkImageData.h>
#include <vtkImageCast.h>
#include <vtkPointData.h>
#include <vtkImageShiftScale.h>
#include <vtkPolyDataToImageStencil.h>
#include <vtkImageStencil.h>
#include <vtkLookupTable.h>
#include <vtkImagePlaneWidget.h>
#include <vtkCellArray.h>
#include <vtkType.h>
#include <vtkProperty.h>
#include <vtkCommand.h>
#include <vtkProbeFilter.h>
#include <vtkImplicitPlaneWidget.h>
#include <vtkClipPolyData.h>
#include <vtkSmartVolumeMapper.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkCamera.h>
#include <vtkRendererCollection.h>
#include <vtkNamedColors.h>
#include <vtkPropPicker.h>
#include <vtkImplicitPlaneRepresentation.h>
#include <vtkImplicitPlaneWidget2.h>
#include <vtkAxesActor.h>
#include <vtkTextProperty.h>
#include <vtkCaptionActor2D.h>
#include <vtkTextActor.h>
#include <vtkCylinderSource.h>
#include <vtkAutoInit.h>
#include <vtkPointPicker.h>
#include <vtkCellPicker.h>
#include <vtkTransform.h>
#include <vtkLinearTransform.h>
#include <vtkAssembly.h>
#include <vtkOrientationMarkerWidget.h>
#include <vtkOutlineFilter.h>
#include <vtkVertex.h>
#include <vtkSphereSource.h>
#include <vtkMultiBlockDataSet.h>
#include <vtkCompositeDataGeometryFilter.h>
#include <vtkIntersectionPolyDataFilter.h>

#include <vtkParametricEllipsoid.h>
#include <vtkParametricFunctionSource.h>
#include <vtkLight.h>
#include <vtkTransformFilter.h>
#include <typeinfo>

```

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [October 26, 2023, 7:22pm UTC](https://discourse.vtk.org/t/how-to-debug-this-error-when-program-is-running/12488/25 "2023-10-26T19:22:04Z")

</div>

Are those all the includes of all the source files in the program?

---

<div class="post-metadata">

### Author: ![Dylan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dylan/32/7822_2.png) [@Dylan](https://discourse.vtk.org/u/Dylan)
#### Post date: [October 27, 2023, 1:58pm UTC](https://discourse.vtk.org/t/how-to-debug-this-error-when-program-is-running/12488/26 "2023-10-27T13:58:19Z")

</div>

The same applies to other class files, which only contain vtk related files

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [October 28, 2023, 12:14pm UTC](https://discourse.vtk.org/t/how-to-debug-this-error-when-program-is-running/12488/27 "2023-10-28T12:14:31Z")

</div>

If that’s all, then you’re using a basic default GUI API, likely something GLUT-like. This makes pixel format mismatch unlikely. Then I believe you have to work out the other points discussed further above.

---

<div class="post-metadata">

### Author: ![Dylan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dylan/32/7822_2.png) [@Dylan](https://discourse.vtk.org/u/Dylan)
#### Post date: [October 30, 2023, 1:29pm UTC](https://discourse.vtk.org/t/how-to-debug-this-error-when-program-is-running/12488/28 "2023-10-30T13:29:38Z")

</div>

Yes, PC, following your suggestion, I called WaitForCompletion() and the frequency of this error indeed decreased. I’m not sure if it’s just my perception, but it does seem to occur less often. I think it might be necessary for me to integrate this code into Qt and then address this error？

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [October 31, 2023, 11:26am UTC](https://discourse.vtk.org/t/how-to-debug-this-error-when-program-is-running/12488/29 "2023-10-31T11:26:46Z")

</div>

No, I don’t think so. Try reducing your problem to a trivial case, that is, render to a single window and observe. Then enable a second window and observe and so on. You will reach a point when you’ll get the errors. Then you need to add that check to avoid it.

One question you didn’t answer is whether your program renderes from multiple threads. Is that so?

---

<div class="post-metadata">

### Author: ![Dylan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dylan/32/7822_2.png) [@Dylan](https://discourse.vtk.org/u/Dylan)
#### Post date: [October 31, 2023, 12:10pm UTC](https://discourse.vtk.org/t/how-to-debug-this-error-when-program-is-running/12488/30 "2023-10-31T12:10:21Z")

</div>

> [@Paulo\_Carvalho](#):
>
> One question you didn’t answer is whether your program renderes from multiple threads. Is that so?

I show the windows like the code as follow, I think it’s single thread:

```auto
interactor_a->Initialize();
interactor_b->Initialize();
interactor_c->Initialize();
interactor_a->start();
interactor_b->start();
interactor_c->start();

```

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [October 31, 2023, 12:44pm UTC](https://discourse.vtk.org/t/how-to-debug-this-error-when-program-is-running/12488/31 "2023-10-31T12:44:34Z")

</div>

Ok, right. Then try reducing your problem to a trivial case, that is, render to a single window and observe. Then enable a second window and observe and so on. You will reach a point when you’ll get the errors. Then you need to add that check to avoid it.

---

<div class="post-metadata">

### Author: ![Dylan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dylan/32/7822_2.png) [@Dylan](https://discourse.vtk.org/u/Dylan)
#### Post date: [October 31, 2023, 12:48pm UTC](https://discourse.vtk.org/t/how-to-debug-this-error-when-program-is-running/12488/32 "2023-10-31T12:48:03Z")

</div>

yeah, that’s a good method to adrress the error. I would try it.  
Thank you very much, PC

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [October 31, 2023, 12:51pm UTC](https://discourse.vtk.org/t/how-to-debug-this-error-when-program-is-running/12488/33 "2023-10-31T12:51:59Z")

</div>

From my experience, reducing to trivial case and proceed to cycles of slowly increasing complexity-and-observe is the best approach to tackle non-deterministic errors like that.

---

<div class="post-metadata">

### Author: ![Dylan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dylan/32/7822_2.png) [@Dylan](https://discourse.vtk.org/u/Dylan)
#### Post date: [October 31, 2023, 1:06pm UTC](https://discourse.vtk.org/t/how-to-debug-this-error-when-program-is-running/12488/34 "2023-10-31T13:06:31Z")

</div>

This is a valid approach, although it may be slow for my code because many global variables are shared among the windows to synchronize interactive operations. However, I will give it a try.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [October 31, 2023, 1:57pm UTC](https://discourse.vtk.org/t/how-to-debug-this-error-when-program-is-running/12488/35 "2023-10-31T13:57:58Z")

</div>

> [@Dylan](#):
>
> many global variables

That’s a no-no in modern software design. You need additional care in presence of global variables. Better to try to get rid of them ASAP. There are better, modern approaches to system-wide notification mechanism such as signal-slots, functors, mutexes/semaphores and the Observer design parttern.

---

<div class="post-metadata">

### Author: ![Dylan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dylan/32/7822_2.png) [@Dylan](https://discourse.vtk.org/u/Dylan)
#### Post date: [October 31, 2023, 2:24pm UTC](https://discourse.vtk.org/t/how-to-debug-this-error-when-program-is-running/12488/36 "2023-10-31T14:24:09Z")

</div>

> [@Paulo\_Carvalho](#):
>
> signal-slots, functors, mutexes/semaphores and the Observer design parttern

Yes, you’re right， PC. The synchronization issue with multiple window interaction has been troubling me for a while, and using global variables has proven to be a cumbersome and risky approach. I really appreciate your recommendations for better methods such as signal-slots, functors, mutexes/semaphores, and the Observer design pattern. I will search for resources to learn and apply these methods.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [November 1, 2023, 10:57am UTC](https://discourse.vtk.org/t/how-to-debug-this-error-when-program-is-running/12488/37 "2023-11-01T10:57:30Z")

</div>

Since you’re not using Qt yet, I suggest you to take a look at Boost’s signals and slots. Please, take a look at this: [Complete example using Boost::Signals for C++ Eventing - Stack Overflow](https://stackoverflow.com/questions/768351/complete-example-using-boostsignals-for-c-eventing)

The Boost library is somewhat intimidating at first glance, but it is very well designed, it is peer-reviewed and almost as reliable as the C++ Standard Library itself. Actually, much of STL features were ported from Boost sometime.

Alternativelly, you may want to implement an Observer in your program: [Understanding and Implementing Observer Pattern in C++ - CodeProject](https://www.codeproject.com/Articles/328365/Understanding-and-Implementing-Observer-Pattern-2)

---

<div class="post-metadata">

### Author: ![Dylan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dylan/32/7822_2.png) [@Dylan](https://discourse.vtk.org/u/Dylan)
#### Post date: [November 1, 2023, 1:12pm UTC](https://discourse.vtk.org/t/how-to-debug-this-error-when-program-is-running/12488/38 "2023-11-01T13:12:05Z")

</div>

Thank you so much, PC. The Observer pattern is indeed what I’m looking for.  
I will study the links you provided carefully. Thanks again!

[Previous page](https://discourse.vtk.org/t/how-to-debug-this-error-when-program-is-running/12488.md?page=1)
