ROOTR (ROOT R interface) problems with X11 graphics

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)”, I noticed that the “${ROOTSYS}/tutorials/r/Interpolation.C” 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:

[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” macro:

// ...
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:

{
  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”).

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

Omar

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

hello @Wile_E_Coyote
I sent this PR with the fix, 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

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