// limit = loop limit. If limit=2 get segfault 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 ); for( j=0; jDraw(); p1->Divide(2,1); for( i=0; i<2; i++ ) { p1->cd(i+1); h[i]->Draw(); // Change size of stats box // This has seg fault second time through loop on gPad-Update() gPad->Update(); //needed in order to find stats box TPaveStats *stats = (TPaveStats*) h[i]->GetListOfFunctions()->FindObject("stats"); x1 = 2.*stats->GetX1NDC() - stats->GetX2NDC(); stats->SetX1NDC(x1); gPad->Modified(); //needed to actually execute change of size gPad->Update(); } } }