Crash when drawing a TH1D defined as a class member

Hello fellow ROOT users,

I am encountering a very strange segmentation fault and would be very grateful for all hints where the problem might be or how to resolve it. It could also be a bug, but i would like to post my problem in the forum first, maybe there is just a simple mistake.

In the file test.C I define this class

class testclass
{
public:
    TH1D* hist;
};

I can now load the file and use the class, for example like this

.L test.C
testclass t;
t.hist = new TH1D("hist","Test",100,-5.0,5.0);
t.hist->FillRandom("gaus",5000);

I can further access and modify the histogram t.hist, but when I wish to draw it, a crash occures

t.hist->Draw();

Leading to:

*** Break *** segmentation violation

===========================================================
There was a crash (#7 0x0109561b in SigHandler(ESignals) () from /usr/local/lib/root/libCore.so).
This is the entire stack trace of all threads:

and a following stack trace. This is strange, because it does not happen when I define the class on the command line. The crash happens after the function gPad->Modified() is called, but i was unable to determine which slots are activated by this signal.

Do you have an Idea how to resolve this problem? Or how to find out which slots are activated by the “Modified()” signal?

Thank you very much in advance,
Jules

1 Like

It seems to work for me. I am using the svn trunk version of ROOT on a Mac:

root [0] .L testclass.C
root [1] testclass t;
root [2] t.hist = new TH1D("hist","Test",100,-5.0,5.0);
root [3] t.hist->FillRandom("gaus",5000);
root [4] t.hist->Draw()
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
root [5] 

[quote=“jules”]Hello fellow ROOT users,

I am encountering a very strange segmentation fault and would be very grateful for all hints where the problem might be or how to resolve it. It could also be a bug
[/code]

Jules[/quote]

It’s a bug.

I did simply this:

[quote]root[0] .L testclass.C
root[1] testclass t;
root[2] TProfile::Class() //that’s what is called from THistPainter::PaintStats
[/quote]
And got the same segmentation violation inside TDataMember.

I agree with Timur. I also get a crash on my IMac. But it is working on my MacBook Pro (as I said before).

And got the same segmentation violation inside TDataMember.[/quote]

Thank you very much. I could also reproduce the crash following your steps and will report it as a bug. I encountered this bug both on my desktop computer (linux x86-64 gcc 4.5.2) and my laptop (linux i386).

Knowing this, I found two ways to work around this bug:
[ul]
[li] Call TProfile::Class() before loading the file[/li]
[li] Or disable the stats via t.hist->SetStats(kFALSE)[/li][/ul]

Again many thanks,
Jules

Hi Jules,

A better work around is to add #include "TH1D.h"to the script and initialize the member variable.

Cheers,
Philippe.

1 Like