Surprising feature of TCanvas

Hi,

A surprising feature of TCanvas:

If I run the code in CINT, it will write the canvas size that I have defined. But if I compile the code (g++ …) and run then it does not care what the size of the canvas I have defined, it always writes the default size (800 x 600).

Thanks.

[quote=“manoj”]Hi,

A surprising feature of TCanvas:

If I run the code in CINT, it will write the canvas size that I have defined. But if I compile the code (g++ …) and run then it does not care what the size of the canvas I have defined, it always writes the default size (800 x 600).

Thanks.[/quote]

Code?

and aslo tell us with version of ROOT you are using and on which machine

Thanks.

This code does not write the defined canvas size:

int main()
{
        TFile *file = new TFile("test.root", "recreate");
        TCanvas *c = new TCanvas("c", "c", 900, 400);
        c->Write();

        file->Close();
}

This code writes the defined canvas size:

int main(int argc, char** argv)
{
        TApplication app("app", &argc, argv);

        TFile *file = new TFile("test.root", "recreate");
        TCanvas *c = new TCanvas("c", "c", 900, 400);
        c->Write();

        file->Close();
        app.Run();
}

This code also writes the defined canvas size:

void test()
{
        TFile *file = new TFile("test.root", "recreate");
        TCanvas *c = new TCanvas("c", "c", 900, 400);
        c->Write();

        file->Close();
}

I tried in Fedora 13 (gcc 4.4.5) with ROOT 5.27/06 and Mac 10.4 (gcc 4.1.2) with ROOT 5.27/04. I used pre-compiled version of ROOT in both cases.

Thanks again.

When you create your own application you should declare a TApplication. So it is normal this code does not work properly.

That’s an interesting issue. You seem to suggest that if one uses ROOT libraries, one needs to create a TApplication object. A similar issue has been reported here [url]Strange behavior reading TFile in Windows where a creation of a TApplication object helped on Widows. Is this precisely described somewhere?

See as example $ROOTSYS/test/stressGraphics.cxx

The question is not “how?”. The questions are “what for?”, “why at all?”, “when is it required?”, “when can it be safely skipped?”.

Bertrand gave you all the details here:

I have nothing to add.

Sorry, but I must disagree.
The outcome of the discussion [quote] https://root-forum.cern.ch/t/strange-behavior-reading-tfile-in-windows/12063/1[/quote] was that due to a Window’s linker idiosyncrasy, one needs to “enforce” loading of the “Hist” library. Apparently, one of the side effects of the creation of a TApplication object is that the “Hist” library is also lined in. But still, there was NO need to create it - one is free to load the “Hist” library manually (without creating the TApplication object, and in fact on LInux even the “manual loading” was not needed at all).
Now, your statement in the current topic is significantly different. You say that is is REQUIRED to create a TApplication object, otherwise the application misbehaves.
So the questions are … “when is it required?” and “when can it be safely skipped?”.

One of the case is when you create a TCanvas.

Yes, that’s what I’ve understood from your post of Mar 22, 2011 10:24. But still … “Is this issue precisely described somewhere?”

Could you, please, raise this issue on some ROOT team’s internal forum?
I believe, it would be useful if this issue was precisely and clearly documented somewhere.