Peculiar crash regarding canvases

The following code crashes if I run the ringer() function. Strangely enough, if I open any canvas first and close it, it will work. Alternatively, commenting out the extraneous “for” loop accomplishes the same.

void sDraw (TText *t)
{
  const char canvasName[] = "c1";

  TCanvas *c;

  if (gROOT->FindObject(canvasName) == NULL) {
    c = new TCanvas(canvasName, canvasName);
  } else c = (TCanvas*)gROOT->FindObject(canvasName);

  t->Draw();
}

void ringer( ) 
{
  // TCanvas *c1 = new TCanvas("c1","threshold finding", 200,10,1200,600);
  TText *t = new TText(0.5,0.5,"Hello World");
  
  for (int i=0; i < 1; i++ ) {
      sDraw(t);
  }
}

Hi,

Try to add gSystem->Load(“libGpad”); at the beginning of your script, to load and properly initialize the graphics libraries. For example:

void ringer( ) { gSystem->Load("libGpad"); // TCanvas *c1 = new TCanvas("c1","threshold finding", 200,10,1200,600); TText *t = new TText(0.5,0.5,"Hello World"); ...
Cheers, Bertrand.