# using vtkWarningMacro in a thread stops abruptly this last (vtkOutputWindow thread safety)

**URL:** https://discourse.paraview.org/t/using-vtkwarningmacro-in-a-thread-stops-abruptly-this-last-vtkoutputwindow-thread-safety/611
**Category:** Development
**Created:** [September 20, 2018, 3:04pm UTC](https://discourse.paraview.org/t/using-vtkwarningmacro-in-a-thread-stops-abruptly-this-last-vtkoutputwindow-thread-safety/611 "2018-09-20T15:04:59Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![embeddedmz](https://discourse.paraview.org/user_avatar/discourse.paraview.org/embeddedmz/32/142_2.png) [@embeddedmz](https://discourse.paraview.org/u/embeddedmz)
#### Post date: [September 20, 2018, 3:05pm UTC](https://discourse.paraview.org/t/using-vtkwarningmacro-in-a-thread-stops-abruptly-this-last-vtkoutputwindow-thread-safety/611/1 "2018-09-20T15:05:00Z")

</div>

Hello,

When I use vtkWarningMacro in another thread in my writer class in Catalyst, I don’t have any issues.

However, when I use my writer in ParaView, to save a result, vtkWarningMacro stops abruptly the thread launched by my writer, in other words : it crashes the thread !

When I was developing in C++ under Windows, I remember that a crash produced in a thread stops the whole application, here I don’t understand how a thread can be stopped abruptly and the program continue its execution.

In the callstack I can see that vtkOutputWindow is handled differently than in Catalyst (that’s normal, as messages are displayed in a widget).

I want to know why I can’t use vtkWarningMacro in a thread in ParaView client and how to fix that.

Thanks.

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [September 24, 2018, 11:32am UTC](https://discourse.paraview.org/t/using-vtkwarningmacro-in-a-thread-stops-abruptly-this-last-vtkoutputwindow-thread-safety/611/2 "2018-09-24T11:32:10Z")

</div>

Is it possible to create a small example to reproduce this issue? If so, it would be great to report this on the [issue tracker](https://gitlab.kitware.com/paraview/paraview/issues) so we can track it down.

---

<div class="post-metadata">

### Author: ![embeddedmz](https://discourse.paraview.org/user_avatar/discourse.paraview.org/embeddedmz/32/142_2.png) [@embeddedmz](https://discourse.paraview.org/u/embeddedmz)
#### Post date: [September 28, 2018, 9:50am UTC](https://discourse.paraview.org/t/using-vtkwarningmacro-in-a-thread-stops-abruptly-this-last-vtkoutputwindow-thread-safety/611/3 "2018-09-28T09:50:59Z")

</div>

Here, I managed to freeze the app and crash the thread :

```auto
    #include <thread>
    #include <vtkObject.h>
    #include <vtkSetGet.h>
    #include <vtkNew.h>

    class DummyVtkObjectClass : public vtkObject
    {
    public:
        static DummyVtkObjectClass* New();
        vtkTypeMacro(DummyVtkObjectClass, vtkObject)

        void PrintAndCrash() { vtkWarningMacro(<< "Crash this app now !"); }
    };

    class myMainWindow : public QMainWindow {
        Q_OBJECT

    public:
        std::thread crashTestThread;
        vtkNew<DummyVtkObjectClass> testSubject;
        void CrashTestMethod()
        {
            // pause until things get set up
            std::this_thread::sleep_for(std::chrono::seconds(30));
            testSubject->PrintAndCrash();
        }
    ...
    };

    myMainWindow::myMainWindow(QWidget* parent)
        : QMainWindow(parent)
        , ui(new Ui::myMainWindow),
          crashTestThread(&myMainWindow::CrashTestMethod, this)
    {
    ...
    }

```

PS : it is possible to have a button to paste a C++ code in this board ???

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [September 28, 2018, 12:07pm UTC](https://discourse.paraview.org/t/using-vtkwarningmacro-in-a-thread-stops-abruptly-this-last-vtkoutputwindow-thread-safety/611/4 "2018-09-28T12:07:10Z")

</div>

Thanks, @embeddedmz. I’ll try it out later today.

> [@embeddedmz](#):
>
> PS : it is possible to have a button to paste a C++ code in this board ???

I am not sure why you need that. You can always just enter any code by enclosing in it 3 ticks e.g. below:

```c++
int foo = 12;
class MyClass : public QWidget
{
};

```

written as:

````
```c++
int foo = 12;
class MyClass : public QWidget
{
};
```

````

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [September 28, 2018, 12:08pm UTC](https://discourse.paraview.org/t/using-vtkwarningmacro-in-a-thread-stops-abruptly-this-last-vtkoutputwindow-thread-safety/611/5 "2018-09-28T12:08:39Z")

</div>

There is a button anyway. Juste select some code and click on the “Preformated Text” button.

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [September 29, 2018, 2:06pm UTC](https://discourse.paraview.org/t/using-vtkwarningmacro-in-a-thread-stops-abruptly-this-last-vtkoutputwindow-thread-safety/611/6 "2018-09-29T14:06:34Z")

</div>

> [@embeddedmz](#):
>
> Here, I managed to freeze the app and crash the thread :

doesnt’ crash for me, I am afraid. Attached is the patch I used for ParaView’s default main window to emulate your code. My test was with ParaView latest release branch.

[mainwindow.patch](https://discourse.paraview.org/uploads/default/original/1X/4958898ce5cff59aab71885a1f8f31d1c44b8cf4.patch) (2.2 KB)

---

<div class="post-metadata">

### Author: ![embeddedmz](https://discourse.paraview.org/user_avatar/discourse.paraview.org/embeddedmz/32/142_2.png) [@embeddedmz](https://discourse.paraview.org/u/embeddedmz)
#### Post date: [October 3, 2018, 3:47pm UTC](https://discourse.paraview.org/t/using-vtkwarningmacro-in-a-thread-stops-abruptly-this-last-vtkoutputwindow-thread-safety/611/7 "2018-10-03T15:47:31Z")

</div>

I forgot to say that I am using Paraview 5.4.1 under Centos 7, apparently this issue disappeared in the latter versions !
