TApplication Canvas Not Responding

Hi. I was writing some standalone ROOT code that works as an event display, when I realized that the canvas won’t open on my computer. I reduced the problem to a simplified piece of code, shown below:

#include "TApplication.h"
#include "TCanvas.h"
#include "TPaveLabel.h"
#include "TROOT.h"

int main(int argc, char **argv)
{
  TApplication* theApp = new TApplication("App", &argc, argv);

  TCanvas *c = new TCanvas("c", "The Hello Canvas", 400, 400);
  TPaveLabel *hello = new TPaveLabel(0.2,0.4,0.8,0.6,"Hello World");
  hello->Draw();
  c->Modified();
  c->Update();
  getchar();
  return 0;
}

On my computer, the graphics never appear. It seems almost as though they are opened (I see the little root.exe icon appear at the bottom of my screen with the other applications), but then I get the spinning wheel of death, and when I pull up the task manager it says ROOT is ‘not responding’.

I am using Mac OSX (High Sierra 10.13.2). I have tried with 3 different versions of ROOT–all to no avail. These include root version 5.34, 6.06, and 6.11. I have tested to make sure X11 is working (I can pull up xclock, for example). I should note that if I include a line ‘theApp->Run()’ in the code, I can get the canvas to appear.

I am stumped. This example seems to work fine on other’s computers, with the same versions of ROOT. I realize that will make my problem hard for others to debug, but I thought I’d give it a chance. Thanks in advance.

Hi,

To get interactivity, you should call theApp->Run();

Regards,
Sergey

It’s not a matter of wanting interactivity. It is that I want the canvas to appear. From what I understand, it should appear with only the lines of code that I included in my first example.

But why you don’t want to call theApp->Run() if it works for you.
Probably, you can call gSystem->ProcessEvents() instead, but this is more or less the same.

Because the original event display code I would like to use does not use theApp->Run(). Instead, it updates the canvas each time it gets user input on the keyboard. Here is the relevant piece of code. It was written by a colleague:

do{
      std::cout << "Press enter for next event or 'b' and then enter for previous event." << std::endl << std::endl;
      termin = std::cin.get();
      if((termin == 'b' || termin == 'B') && eventN > 1) {
        termin = std::cin.get();
        eventN -= 2;
      }
      st.str("");
      st << eventN;
      title_pad->cd();
      eventN_text.Clear();
      eventN_text.AddText(st.str().c_str());
      title_pad->Modified();
      std::cout << "Event # " << eventN << std::endl;
      flat_tree->GetEntry(eventN++);
      UpdateDisplay(event_map);
      } while(true);

Where the function UpdateDisplay(event_map) calls the update() command on the canvas. It works OK on two other machine’s (his and another coworker’s). I would rather not modify this code to include theApp->Run(). I shouldn’t have to, since it works on theirs.

Are these also Mac OSX (High Sierra 10.13.2)?

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