Minor bug in TPad and TLegend

Dear ROOT developers,
I was trying to plot a histogram with a transparent TLegend in a TPad.
The problem is that the histogram was deleted when I drew the TLegend.
A simple code reproducing the bug is the following.

TH1F histo("histo","",100,-1,1); histo.FillRandom("gaus",100); TCanvas c1("c1",""); TPad pad1("pad1","",0.1,0.1,0.9,0.9); pad1.Draw(); pad1.cd(); histo.Draw(); TLegend leg(0.7,0.7,0.85,0.85); leg.AddEntry(&histo,"histo","l") leg.SetFillStyle(4000) leg.Draw();

Note that if you remove the pad1 definition, everything works properly.

Finally, I’ve found out that the problem was in “leg.SetFillStyle(4000)”. I had to use use “leg.SetFillStyle(0)” [1].

Even if I solved the problem, I think that this behaviour is a (minor) bug and so I wanted to report it to you.


[1] root.cern.ch/root/roottalk/roottalk03/1079.html
[2] root.cern.ch/doc/v608/classTAttFill.html

yes that’s the right way … so what is wrong ?

I’ve just noticed that in root.cern.ch/doc/master/classTAttFill.html
you actually specified "For TPad only: 4000 …"
It would be nice to have a warning or an error if you attempt to set a wrong FillStyle (>4000).
In any case, the fact that the plot is deleted if you draw a legend with a wrong FillStyle looks to me very bizarre, especially because it doesn’t happen if you use directly a TCanvas.


The Attributes classes are very low classes called zillion of time when a plot is done. Putting any kind of check at such low level may have a non negligible effect on performances. That’s what it was chosen to document the various features.