# vtkXRenderWindowInteractor: ProcessEvents does not work

**URL:** https://discourse.vtk.org/t/vtkxrenderwindowinteractor-processevents-does-not-work/2969
**Category:** Development
**Created:** [April 6, 2020, 12:35pm UTC](https://discourse.vtk.org/t/vtkxrenderwindowinteractor-processevents-does-not-work/2969 "2020-04-06T12:35:56Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![TomLKoller](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/45deac/32.png) [@TomLKoller](https://discourse.vtk.org/u/TomLKoller)
#### Post date: [April 6, 2020, 12:35pm UTC](https://discourse.vtk.org/t/vtkxrenderwindowinteractor-processevents-does-not-work/2969/1 "2020-04-06T12:35:56Z")

</div>

The ProcessEvents() method of vtkRenderWindowInteractor can be used to implement custom event loops.

I used the method on a Ubuntu LTs 18.04 Machine with vtk 9.  
My setup worked when i called the Start() method but not when i called ProcessEvents() in my custom loop.

Looking into the source code the vtkXRenderWindowInteractor (the ubuntu subclass) uses a BreakLoopFlag instead of the Common Done flag to handle the loop in the StartEventLoop method (Done is used in all other vtkRenderWindowInteractor subclasses).

The BreakLoopFlag can not be accessed from the BaseClass and it is initialized at 1, which causes ProcessEvents() to immediately return without processing any events.

So i guess this is an implementation bug and the vtkXRenderWindowInteractor should be changed to use the Done flag which is accessible from the base class.

---

<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: [April 6, 2020, 2:25pm UTC](https://discourse.vtk.org/t/vtkxrenderwindowinteractor-processevents-does-not-work/2969/2 "2020-04-06T14:25:12Z")

</div>

Cc: @ken-martin

---

<div class="post-metadata">

### Author: ![ken-martin](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ken-martin/32/884_2.png) [@ken-martin](https://discourse.vtk.org/u/ken-martin)
#### Post date: [April 6, 2020, 3:19pm UTC](https://discourse.vtk.org/t/vtkxrenderwindowinteractor-processevents-does-not-work/2969/3 "2020-04-06T15:19:59Z")

</div>

Tom can you try your suggested change and see if it works? If so you or I can whip up a quick MR for it.

---

<div class="post-metadata">

### Author: ![TomLKoller](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/45deac/32.png) [@TomLKoller](https://discourse.vtk.org/u/TomLKoller)
#### Post date: [April 6, 2020, 3:38pm UTC](https://discourse.vtk.org/t/vtkxrenderwindowinteractor-processevents-does-not-work/2969/4 "2020-04-06T15:38:17Z")

</div>

I tested it and it works. I would be happy if you do the MR, but apparently i cant upload the fixed files.

---

<div class="post-metadata">

### Author: ![ken-martin](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ken-martin/32/884_2.png) [@ken-martin](https://discourse.vtk.org/u/ken-martin)
#### Post date: [April 6, 2020, 4:52pm UTC](https://discourse.vtk.org/t/vtkxrenderwindowinteractor-processevents-does-not-work/2969/5 "2020-04-06T16:52:00Z")

</div>

Can paste a diff here, if so I’ll create the MR etc

---

<div class="post-metadata">

### Author: ![TomLKoller](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/45deac/32.png) [@TomLKoller](https://discourse.vtk.org/u/TomLKoller)
#### Post date: [April 6, 2020, 4:57pm UTC](https://discourse.vtk.org/t/vtkxrenderwindowinteractor-processevents-does-not-work/2969/6 "2020-04-06T16:57:25Z")

</div>

Diffs of the header and source. Maybe ive gone a bit over board and removed all functions with BreakLoopFlag (which are unneccessary), which may break existing implementations that specifically used vtkXRenderWindowInteractor.

If this is an issue just change  
BreakLoopFlagOff and On to set Done instead of BreakLoopFlag.

diff --git a/Rendering/UI/vtkXRenderWindowInteractor.h b/Rendering/UI/vtkXRenderWindowInteractor.h  
index d5555cafde…f6fe969d51 100644  
— a/Rendering/UI/vtkXRenderWindowInteractor.h  
+++ b/Rendering/UI/vtkXRenderWindowInteractor.h  
@@ -65,18 +65,6 @@ public:  
\*/  
void ProcessEvents() override;

- //@{

- /\*\*

- 
  - The BreakLoopFlag is checked in the Start() method.

- 
  - Setting it to anything other than zero will cause

- 
  - the interactor loop to terminate and return to the

- 
  - calling function.

- \*/

- vtkGetMacro(BreakLoopFlag, int);

- void SetBreakLoopFlag(int);

- void BreakLoopFlagOff();

- void BreakLoopFlagOn();

- //@}

- static int BreakLoopFlag;

diff --git a/Rendering/UI/vtkXRenderWindowInteractor.cxx b/Rendering/UI/vtkXRenderWindowInteractor.cxx  
index 0cce4d9771…fead37c302 100644  
— a/Rendering/UI/vtkXRenderWindowInteractor.cxx  
+++ b/Rendering/UI/vtkXRenderWindowInteractor.cxx  
@@ -138,8 +138,6 @@ private:  
std::map\<int, vtkXRenderWindowInteractorTimer\> LocalToTimer;  
};

## -int vtkXRenderWindowInteractor::BreakLoopFlag = 1;

// for some reason the X11 def of KeySym is getting messed up  
typedef XID vtkKeySym;

@@ -172,12 +170,12 @@ vtkXRenderWindowInteractor::~vtkXRenderWindowInteractor()  
// This results in Start() returning to its caller.  
void vtkXRenderWindowInteractor::TerminateApp()  
{

- if (this-\>BreakLoopFlag)

- if (this-\>Done)  
{  
return;  
}

- this-\>BreakLoopFlag = 1;

- this-\>Done=1;

-void vtkXRenderWindowInteractor::SetBreakLoopFlag(int f)  
-{

- if (f)
- {
- this-\>BreakLoopFlagOn();
- }
- else
- {
- this-\>BreakLoopFlagOff();
- }  
-}
- 

-void vtkXRenderWindowInteractor::BreakLoopFlagOff()  
-{

- this-\>BreakLoopFlag = 0;
- this-\>Modified();  
-}
- 

-void vtkXRenderWindowInteractor::BreakLoopFlagOn()  
-{

- this-\>TerminateApp();
- this-\>Modified();  
-}
- 

void vtkXRenderWindowInteractor::ProcessEvents()  
{  
XEvent event;

- while (XPending(this-\>DisplayId) && this-\>BreakLoopFlag == 0)

- while (XPending(this-\>DisplayId) && this-\>Done == 0)  
{  
XNextEvent(this-\>DisplayId, &event);  
this-\>DispatchEvent(&event);  
@@ -242,7 +216,7 @@ void vtkXRenderWindowInteractor::StartEventLoop()  
fd\_set in\_fds;  
struct timeval tv;

- this-\>BreakLoopFlag = 0;

- this-\>Done = 0;  
do  
{  
if (XPending(this-\>DisplayId) == 0)  
@@ -267,7 +241,7 @@ void vtkXRenderWindowInteractor::StartEventLoop()  
this-\>DispatchEvent(&event);  
}  
this-\>FireTimers();

- } while (this-\>BreakLoopFlag == 0);

- } while (this-\>Done == 0);  
}

//-------------------------------------------------------------------------  
@@ -384,7 +358,7 @@ void vtkXRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent)  
{  
this-\>Superclass::PrintSelf(os, indent);

- os \<\< indent \<\< "BreakLoopFlag: " \<\< (this-\>BreakLoopFlag ? “On\n” : “Off\n”);

- os \<\< indent \<\< "Done: " \<\< (this-\>Done ? “Yes\n” : “No\n”);  
}

//-------------------------------------------------------------------------

---

<div class="post-metadata">

### Author: ![ken-martin](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ken-martin/32/884_2.png) [@ken-martin](https://discourse.vtk.org/u/ken-martin)
#### Post date: [April 6, 2020, 6:00pm UTC](https://discourse.vtk.org/t/vtkxrenderwindowinteractor-processevents-does-not-work/2969/7 "2020-04-06T18:00:35Z")

</div>

Thanks MR here [https://gitlab.kitware.com/vtk/vtk/-/merge\_requests/6687](https://gitlab.kitware.com/vtk/vtk/-/merge_requests/6687)
