ROOT crashes when manipulating on pads

Hello,

in my program I have to manipulate many histograms and canvases, like changing title/label offset/size or pad margins. For this I wrote small library which contains all such functions (which are analysis independent) and can be use for several projects.

One of the functions in library sets pad margins:

void RootTools::NicePad(TVirtualPad * pad, Float_t mT, Float_t mR, Float_t mB, Float_t mL) { pad->SetTopMargin(mT); pad->SetBottomMargin(mB); pad->SetLeftMargin(mL); pad->SetRightMargin(mR); }

The RootTools is a namespace;

There is another function which exports canvas to the PNG file:

void ExportPNG(TCanvas * can, const TString & path) { TImage * img = TImage::Create(); img->FromPad(can); TString filename = path + TString::Format("%s.png", can->GetName()); img->WriteImage(filename); delete img; }

Whole program has more less following structure:

[code]TCanvas * can = …
TH1 * h = …
can->cd();
h->Draw();
RootTools::NicePad(gPad, 0.9, 0.9, 0.1, 0.1);
ExportPng(can, “/tmp/”);

Problem occurs when I call ‘NicePad’ function, program crashes with following output

[quote] *** Break *** segmentation violation

===========================================================
There was a crash (#7 0x08ac153d in SigHandler(ESignals) () from /home/halo/install/root/534-05/lib/root/libCore.so.5.34).
This is the entire stack trace of all threads:

#0 0x00616430 in __kernel_vsyscall ()
#1 0x01bc83a3 in __waitpid_nocancel () from /lib/libc.so.6
#2 0x01b61ef3 in do_system () from /lib/libc.so.6
#3 0x009137ed in system () from /lib/libpthread.so.0
#4 0x08abbcbd in TUnixSystem::Exec(char const*) () from /home/halo/install/root/534-05/lib/root/libCore.so.5.34
#5 0x08ac211d in TUnixSystem::StackTrace() () from /home/halo/install/root/534-05/lib/root/libCore.so.5.34
#6 0x08ac142f in TUnixSystem::DispatchSignals(ESignals) () from /home/halo/install/root/534-05/lib/root/libCore.so.5.34
#7 0x08ac153d in SigHandler(ESignals) () from /home/halo/install/root/534-05/lib/root/libCore.so.5.34
#8 0x08ab81d2 in sighandler(int) () from /home/halo/install/root/534-05/lib/root/libCore.so.5.34
#9
#10 0x01d85149 in TASImage::FillRectangleInternal(unsigned int, int, int, unsigned int, unsigned int) () from /home/halo/install/root/534-05/lib/root/libASImage.so
#11 0x01d8a1a5 in TASImage::FillRectangle(char const*, int, int, unsigned int, unsigned int) () from /home/halo/install/root/534-05/lib/root/libASImage.so
#12 0x01d826d2 in TASImage::DrawBox(int, int, int, int, char const*, unsigned int, int) () from /home/halo/install/root/534-05/lib/root/libASImage.so
#13 0x0094139f in TImageDump::DrawBox(double, double, double, double) () from /home/halo/install/root/534-05/lib/root/libPostscript.so.5.34
#14 0x0066c93e in TPad::PaintBox(double, double, double, double, char const*) () from /home/halo/install/root/534-05/lib/root/libGpad.so.5.34
#15 0x00a7f2f8 in TBox::PaintBox(double, double, double, double, char const*) () from /home/halo/install/root/534-05/lib/root/libGraf.so.5.34
#16 0x00ad2f16 in TWbox::PaintWbox(double, double, double, double, short, short, short) () from /home/halo/install/root/534-05/lib/root/libGraf.so.5.34
#17 0x00ad2e8f in TWbox::Paint(char const*) () from /home/halo/install/root/534-05/lib/root/libGraf.so.5.34
#18 0x00a8d391 in TFrame::Paint(char const*) () from /home/halo/install/root/534-05/lib/root/libGraf.so.5.34
#19 0x006602b8 in TPad::Paint(char const*) () from /home/halo/install/root/534-05/lib/root/libGpad.so.5.34
#20 0x006456de in TCanvas::Paint(char const*) () from /home/halo/install/root/534-05/lib/root/libGpad.so.5.34
#21 0x01d8dedf in TASImage::FromPad(TVirtualPad*, int, int, unsigned int, unsigned int) () from /home/halo/install/root/534-05/lib/root/libASImage.so
#22 0x004d6ce3 in RootTools::ExportPNG(TCanvas*, TString const&) () from /home/rlalik/usr/lib/libRootTools.so.5.34.05
#23 0x004d7004 in RootTools::ExportImages(TCanvas*, TString const&) () from /home/rlalik/usr/lib/libRootTools.so.5.34.05
#24 0x004d7285 in RootTools::SaveAndClose(TCanvas*, TFile*, bool, TString const&) () from /home/rlalik/usr/lib/libRootTools.so.5.34.05
#25 0x00927cd7 in ToolsAbstract::SaveAndClose (this=0xffc3fdc8, can=0xa104ab8, export_images=true) at /home/rlalik/hadesdst/pp35/tools/pp35anal/src/ToolsAbstract.cpp:265
#26 0x0804c5ab in SecVertexReco::Finalize (this=0xffc3fdc8) at /home/rlalik/hadesdst/pp35/tools/pp35anal/src/SecVertexReco.cpp:289
#27 0x00927c95 in ToolsAbstract::Proceed (this=0xffc3fdc8) at /home/rlalik/hadesdst/pp35/tools/pp35anal/src/ToolsAbstract.cpp:261
#28 0x0804d5ac in main (argc=14, argv=0xffc3fff4) at /home/rlalik/hadesdst/pp35/tools/pp35anal/src/SecVertexReco.cpp:493

The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.

#10 0x01d85149 in TASImage::FillRectangleInternal(unsigned int, int, int, unsigned int, unsigned int) () from /home/halo/install/root/534-05/lib/root/libASImage.so
#11 0x01d8a1a5 in TASImage::FillRectangle(char const*, int, int, unsigned int, unsigned int) () from /home/halo/install/root/534-05/lib/root/libASImage.so
#12 0x01d826d2 in TASImage::DrawBox(int, int, int, int, char const*, unsigned int, int) () from /home/halo/install/root/534-05/lib/root/libASImage.so
#13 0x0094139f in TImageDump::DrawBox(double, double, double, double) () from /home/halo/install/root/534-05/lib/root/libPostscript.so.5.34
#14 0x0066c93e in TPad::PaintBox(double, double, double, double, char const*) () from /home/halo/install/root/534-05/lib/root/libGpad.so.5.34
#15 0x00a7f2f8 in TBox::PaintBox(double, double, double, double, char const*) () from /home/halo/install/root/534-05/lib/root/libGraf.so.5.34
#16 0x00ad2f16 in TWbox::PaintWbox(double, double, double, double, short, short, short) () from /home/halo/install/root/534-05/lib/root/libGraf.so.5.34
#17 0x00ad2e8f in TWbox::Paint(char const*) () from /home/halo/install/root/534-05/lib/root/libGraf.so.5.34
#18 0x00a8d391 in TFrame::Paint(char const*) () from /home/halo/install/root/534-05/lib/root/libGraf.so.5.34
#19 0x006602b8 in TPad::Paint(char const*) () from /home/halo/install/root/534-05/lib/root/libGpad.so.5.34
#20 0x006456de in TCanvas::Paint(char const*) () from /home/halo/install/root/534-05/lib/root/libGpad.so.5.34
#21 0x01d8dedf in TASImage::FromPad(TVirtualPad*, int, int, unsigned int, unsigned int) () from /home/halo/install/root/534-05/lib/root/libASImage.so
#22 0x004d6ce3 in RootTools::ExportPNG(TCanvas*, TString const&) () from /home/rlalik/usr/lib/libRootTools.so.5.34.05
#23 0x004d7004 in RootTools::ExportImages(TCanvas*, TString const&) () from /home/rlalik/usr/lib/libRootTools.so.5.34.05
#24 0x004d7285 in RootTools::SaveAndClose(TCanvas*, TFile*, bool, TString const&) () from /home/rlalik/usr/lib/libRootTools.so.5.34.05
#25 0x00927cd7 in ToolsAbstract::SaveAndClose (this=0xffc3fdc8, can=0xa104ab8, export_images=true) at /home/rlalik/hadesdst/pp35/tools/pp35anal/src/ToolsAbstract.cpp:265
#26 0x0804c5ab in SecVertexReco::Finalize (this=0xffc3fdc8) at /home/rlalik/hadesdst/pp35/tools/pp35anal/src/SecVertexReco.cpp:289
#27 0x00927c95 in ToolsAbstract::Proceed (this=0xffc3fdc8) at /home/rlalik/hadesdst/pp35/tools/pp35anal/src/ToolsAbstract.cpp:261
#28 0x0804d5ac in main (argc=14, argv=0xffc3fff4) at /home/rlalik/hadesdst/pp35/tools/pp35anal/src/SecVertexReco.cpp:493
===========================================================[/quote]

When ‘NicePad’ is not called then program executes fine.

For crosscheck I defined local function ‘NicePad’ and when I call it, program doesn’t crass… Wll, this is not true, because on different machines, it sometimes crasshes when I call each of these two functions, on other it doesn’t crash at all, on another it crash only when ‘RootTools:NicePad’ is called.

I have prepared minimal code which you can compile and test (attached to the post). It is enough to unpack an run build.sh script. it will compile library, then compile small test program which is linked to this library and execute it. It should crash, it should… You can comment/uncomment lines 78/79 of main.cpp to test two solutions - calling line 78 shouldn’t cause crash, calling 79 should crash. When non of these functions is called program never crashes.

I have no idea what may be wrong,
nicepadexample.tar.bz2 (7.81 KB)

Ok, I’ve found reason for this. The problem was with calling

Margins should be given as a distance from the edge not from the origin so it should be

RootTools::NicePad(gPad, 0.1, 0.1, 0.1, 0.1);. But still I don’t understand why sometimes it crashes and sometimes not.

R.