Re: Saving a canvas

Rene Brun (Rene.Brun@cern.ch)
Tue, 02 Sep 1997 17:20:47 +0200


Damir Buskulic wrote:
>
> Hi !
> I tried to use the new feature implemented in root v1.03, namely the
> possibility to save a complete canvas.
> My canvas is created at logon by rootlogon.C. I make changes, draw
> histograms, etc... and save this canvas.
> when I try a new session, the canvas is drawn automaticaly at the
> beginning of the session. To be sure, I close the canvas and do a
> gROOT.Reset()
> When I try to read again by
>
> TFile f("can1.root")
> can1.Draw()
>
> the program crashes
>
> is this a bug or a feature ?
>

Your problem has to do with the scope.
If you create an object can1 in your logon file, then delete
this canvas, the object can1 is deleted from the ROOT tables.
Its destructor has been called. However, it is still know (its anme)
from CINT. Next time you will attempt to use the name can1
(for example in can1.Draw) you will get a crash. You should
proceed as follows (if you insist doing this way)
TCanvas *can1 = new TCanvas("can1") in your logon file
now you can delete the canvas by closing the canvas in the "File" menu
or by the instruction "delete can1". Then, you can:
TFile f("can1.root");
can1 = (TCanvas*)f.Get("can1");
can1->Draw();

Rene Brun