# ROOTR (ROOT R interface) problems with X11 graphics

**URL:** <https://root-forum.cern.ch/t/rootr-root-r-interface-problems-with-x11-graphics/39299>\
**Category:** ROOT\
**Created:** [May 7, 2020, 10:02am UTC](https://root-forum.cern.ch/t/rootr-root-r-interface-problems-with-x11-graphics/39299 "2020-05-07T10:02:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [May 7, 2020, 10:02am UTC](https://root-forum.cern.ch/t/rootr-root-r-interface-problems-with-x11-graphics/39299/1 "2020-05-07T10:02:37Z")

</div>

This is Ubuntu 20.04 LTS / x86\_64 / gcc 9.3.0 with the system provided R 3.6.3 plus the ROOT 6.20/04 tag and / or the “v6-20-00-patches” (2020.05.01) branch here.

While playing with the [“Issues when building ROOT with R statistics (ROOTR)”](https://root-forum.cern.ch/t/issues-when-building-root-with-r-statistics-rootr/39267/9), I noticed that the “[`${ROOTSYS}/tutorials/r/Interpolation.C`](https://root.cern.ch/doc/master/Interpolation_8C.html)” misbehaves:

- sometimes, it draws and immediately closes some canvas,
- sometimes it draws a canvas titled “R Graphics: Device 2 (ACTIVE)” with some contents (sometimes without any), which then remains there all the time.

In any case, usually, ROOT simply “hangs” (several “Ctrl-C” plus “.qqq” needed to exit it).  
Sometimes there are also various strange error messages in the terminal window (occasionally a verbose “\*\*\* Break \*\*\* segmentation violation” appears).

Once there appeared strange error messages which seem to point to the origin of these problems:

```nohighlight
[xcb] Unknown sequence number while processing reply
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
root.exe: ../../src/xcb_io.c:641: _XReply: Assertion `!xcb_xlib_threads_sequence_lost' failed.

```

So, I modified the beginning of the “[`${ROOTSYS}/tutorials/r/Interpolation.C`](https://root.cern.ch/doc/master/Interpolation_8C.html)” macro:

```cpp
// ...
void Interpolation()
{
   // one MUST FIRST initialize multi-threaded X11 (call "XInitThreads")
   if (!gROOT->IsBatch()) delete new TCanvas(); // call "XInitThreads"
   ROOT::R::TRInterface &r=ROOT::R::TRInterface::Instance();
   // ...

```

and indeed, this seems to fix the problem (I tried to run this macro several tens of times and I did not get any more crashes).

Moreover, I think calling “`XInitThreads`” MUST appear BEFORE “`ROOT::R::TRInterface::Instance()`”.  
If I try to exchange the order of these two lines then I still get crashes (not so often as without calling “`XInitThreads`” at all, but they can still appear).

Note: if one wants the canvas to remain displayed, one needs to comment out one line in this tutorial:  
` // r<<"dev.off()";//Required to close new window for plot`

Finally, I have found an even simpler brutal fix, which does not require any changes to the R related tutorials at all. I created a trivial “`rootlogon.C`” file:

```cpp
{
  if (!gROOT->IsBatch()) delete new TCanvas(); // call "XInitThreads"
}

```

Please note that I do not know what is the simplest way to call “`XInitThreads`” in ROOT, so I simply execute “`delete new TCanvas()`”.

Could you, please, implement calling “`XInitThreads`” in some appropriate place in the “`TRInterface`” initialization. It seems to be required “`if (!gROOT->IsBatch())`” but, maybe one should call it in any case (“just a precaution”).

---

<div class="post-metadata">

**Author:** ![omazapa](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/omazapa/32/12711_2.png) [@omazapa](https://root-forum.cern.ch/u/omazapa)\
**Post date:** [May 8, 2020, 8:26am UTC](https://root-forum.cern.ch/t/rootr-root-r-interface-problems-with-x11-graphics/39299/2 "2020-05-08T08:26:01Z")

</div>

Hello @Wile_E_Coyote ,  
We will investigate this issue.  
Best regards

Omar

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 11, 2020, 2:28pm UTC](https://root-forum.cern.ch/t/rootr-root-r-interface-problems-with-x11-graphics/39299/3 "2020-05-11T14:28:49Z")

</div>

@omazapa ,  
There is a Jira Ticket corresponding to that:  
[https://sft.its.cern.ch/jira/browse/ROOT-10755](https://sft.its.cern.ch/jira/browse/ROOT-10755)  
Should we assign it to you ?

---

<div class="post-metadata">

**Author:** ![omazapa](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/omazapa/32/12711_2.png) [@omazapa](https://root-forum.cern.ch/u/omazapa)\
**Post date:** [May 14, 2020, 7:48am UTC](https://root-forum.cern.ch/t/rootr-root-r-interface-problems-with-x11-graphics/39299/4 "2020-05-14T07:48:27Z")

</div>

hello @Wile_E_Coyote  
I sent this PR with the fix, [https://github.com/root-project/root/pull/5608](https://github.com/root-project/root/pull/5608)

I tested it also with Ubuntu 20.04 LTS / x86\_64 / gcc 9.3.0 and R 3.6.3

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [May 28, 2020, 7:48am UTC](https://root-forum.cern.ch/t/rootr-root-r-interface-problems-with-x11-graphics/39299/5 "2020-05-28T07:48:36Z")

</div>

Closed on May 28, 2020, 7:48am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
