Exec3 tutorials crash

Hi,

I’m trying to make a macro based on the code from tutorials/gui/exec3.C.

The original macro works well, but when I modify it (see below), it crashes if I execute it 3 times in a row.
The simplest way to reproduce the problem is the following:

  1. add two lines at the end of exec3() function:

    delete h;
    delete c1;

  2. add three (empty) functions at the end of the file, e.g.:

void sss1(){}
void sss2(){}
void sss3(){}

Here is the text of the macro:

#include <TH1.h>
#include <TCanvas.h>
#include <TQObject.h>

void exec3()
{
   // Example of using signal/slot in TCanvas/TPad to get feedback
   // about processed events. Note that slots can be either functions
   // or class methods. Compare this with tutorials exec1.C and exec2.C.
   //Author: Ilka Antcheva
   
   TH1F *h = new TH1F("h","h",100,-3,3);
   h->FillRandom("gaus",1000);
   TCanvas *c1=new TCanvas("c1");
   h->Draw();
   c1->Update();
   c1->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", 0, 0,
               "exec3event(Int_t,Int_t,Int_t,TObject*)");
   delete h;
   delete c1;
}

void exec3event(Int_t event, Int_t x, Int_t y, TObject *selected)
{
   TCanvas *c = (TCanvas *) gTQSender;
   printf("Canvas %s: event=%d, x=%d, y=%d, selected=%s\n", c->GetName(),
          event, x, y, selected->IsA()->GetName());
}
void sss1(){}
void sss2(){}
void sss3(){}

This is the root output:

ROOT 5.30/04 (tags/v5-30-04@41807, Nov 08 2011, 14:28:58 on linuxx8664gcc)

CINT/ROOT C/C++ Interpreter version 5.18.00, July 2, 2010
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0] .x exec3.C
root [1] .x exec3.C
root [2] .x exec3.C

 *** Break *** segmentation violation
Root > Function exec3() busy flag cleared

There is no error if I execute it by
.L exec3.C
exec3() (many times)

Can anyone reproduce this error? Is it a bug or am I doing something wrong?

I’m running ubuntu 11.10 x86_64, if it’s important…

Thanks,
Yuri.

Hi Yuri,

This is indeed a problem (see savannah.cern.ch/bugs/?91975) that involves CINT and thus we plan on addressing it only when switch over to cling.

In the meantime, you can work around the problem by by calling explicitly:gROOT->GetListOfGlobalFunctions()->Delete();
before reloading the script or at least before reconnecting the signal/slots.

Cheers,
Philippe.