gPad-Update() causes seg fault

I want to write a script does a loop which reads in histograms from a file and plots them on a canvas. My loop also resizes the statistics box of the histogram to make it easier to read. This resizing involves doing a gPad->Update(). On the first loop, this works but on the second loop I get a segfault. I’ve attached a stripped down version of my script which illustrates the problem. I’m using ROOT 5.17/08. Why do I get this segfault?

A secondary question - My method of changing the size of the stats box takes 6 lines of code. Is there an easier way?

Thanks.
ctest.C (997 Bytes)

see a simplified version of your program below. See lines with “<===”

Rene

[code]void ctest( int limit=1 ) {
int i,j;
TH1F *h[2];
Double_t x1;

// Dummy histograms (real ones read from a file)
h[0] = new TH1F(“h0”,"",200,-1.,1.);
h[1] = new TH1F(“h1”,"",152, -0.1, 15.1 );

gStyle->SetStatX(0.9); //<===
gStyle->SetStatW(0.5); //<===
for( j=0; j<limit; j++ ) {
TCanvas *c1 = new TCanvas(Form(“c1%i”,j+1),Form(“c%i”,j+1),1000,500); //<===
// Make subpad for plots (and to leave space for page title)
TPad *p1 = new TPad(“p1”,“p1”,0.0,0.0,1.0,0.9,-1,-1,0);
p1->Draw();
p1->Divide(2,1);
for( i=0; i<2; i++ ) {
p1->cd(i+1);
h[i]->Draw();
}
}
}
[/code]

Thanks for the simpler version of the code. I’m still puzzled why my version had a seg fault, however.

Your version was segfaulting because you were creating two canvases with the same name. When creating the second instance, the first one was deleted, making damage in your local variables.

Rene