Hello,
The following code compiles but segfaults at the marked lines. It runs fine if the lines are commented.
#include "TObjArray.h"
#include "TCanvas.h"
#include "TPad.h"
void testpad() {
TObjArray CanvArray;
TCanvas* canv;
TPad* pad;
char canvname[150];
char padname[10];
for ( Int_t i = 0; i < 6; i++ ) { // Loop over unique energies. 1 canvas per energy.
sprintf(canvname,"Energy_%i",i);
CanvArray.Add( new TCanvas(canvname,canvname) );
canv = dynamic_cast<TCanvas*>(CanvArray[i]);
canv->Divide(3,3);
for (Int_t k = 0; k < 9; k++) { // Loop over pads (9 kinds of histo). canv->cd(k+1);
sprintf(padname,"canv_%i",k+1); pad = (TPad*)(canv->GetPrimitive(padname)); pad->SetBorderSize(1); // causes segfault // pad->SetFillColor(33); // causes segfault // Draw something on each pad.
}//Loop over pads
}// Loop over energies
}
I assume that there is something wrong with the way I'm setting the pointer pad.
Thanks for any help.
Roger Received on Tue Nov 04 2008 - 15:23:20 CET
This archive was generated by hypermail 2.2.0 : Tue Nov 04 2008 - 17:50:02 CET