Re: [ROOT] Segfault in TPostscript constructor?

From: Leon Mualem (mualem@hep.umn.edu)
Date: Wed Feb 20 2002 - 22:05:37 MET


Hi,
I seem to be able to get this error in a CVS version dated 2002/02/14.
I discovered this while investigating a different problem, which I will 
describe here.

I have two very similar versions of a macro, and one make reasonable 
landscape US letter output, while the other doesn't.  The problem would 
manifest itself by the picture being sized too large in the x direction, 
or the short side of a landscape page.  While investigating why, I 
discovered that the TPostScript constructor has a couple of features 
which may be inconvenient, and I think easily corrected.

The first problem is that there are tests on the variable "fType", for 
selecting landscape, portrait, or eps.  The problem is that the actual 
selection of these types are only in the first digit, which is 
calculated as fMode, but then not used in the tests.  This make a 
problem if you want to select a paper type of US letter, by changing 
your fType from the stated types of 111,112,or 113, to 100111,100112, 
and 100113.  The tests for fType will fail, as they are like fType==112, 
while a test like fMode==2 is what is required.

The second, and probably more complicated issue is the coupling to gPad. 
  This is the root of the problem I had.  There may be issues that I 
don't know about not being a postscript expert, or even novice, but I 
did take some time to try to understand what was going on.  If you do 
not have a current gPad, you effectively choose a layout defined by 
gStyle->GetPaperSize(fXsize,fYsize), but apparently get the segfault 
described below, for reasons that are not obvious to me.  It seems the 
only reason for requiring this gPad test is so that you can get the 
scale of the drawing you have done, or are going to do in this gPad 
correct.  However, I don't think this quite works as intended, since it 
only gets the scaling correct for the current Canvas, if you open 
another, it will rescale the drawings to the dimensions of the pad you 
have open at the time. (if I understand correctly.)

It seems like a sensible thing to do, is to have it first grab the 
dimensions of the current paper size, and then, if there is a gPad, 
reset to the size of the current gPad.  Something along the lines of:

gStyle->GetPaperSize(fXsize,fYsize);
Float_t ww=fXsize;
Float_t wh=fYsize;
if(gPad) {
	ww = gPad->GetWw();
	wh = gPad->GetWh();
}

This would then scale a drawing to the page, if there was no gPad 
defined, and if one was defined, it would keep the aspect ratio of the 
current pad.  It probably doesn't handle the .eps case well, but I 
haven't been bitten by this yet, so there may be an elegant solution to 
that, or a better solution than I proposed here.  The experts are free 
to do as they wish, of course.

Leon

> Hi Thomas,
> 
> This happens when you create a TPostScript object before creating a TCanvas.
> Simply create a Tcanvas before this statement.
> The fix is already in the CVS source.
> 
> Rene Brun
> 
> Thomas Kluge wrote:
>> > Hi,
>> > since ROOT 3.02/06 I suffer from this:
>> > ---------------------
>> [h1aac02] ~ $ root
>> *******************************************
>> *                                         *
>> *        W E L C O M E  to  R O O T       *
>> *                                         *
>> *   Version   3.02/06  14 December 2001   *
>> *                                         *
>> *  You are welcome to visit our Web site  *
>> *          http://root.cern.ch *
>> *                                         *
>> *******************************************
>> > FreeType Engine v1.x used to render TrueType fonts.
>> Compiled for linuxsuse6.
>> > CINT/ROOT C/C++ Interpreter version 5.15.21, Dec 8 2001
>> Type ? for help. Commands must be C++ statements.
>> Enclose multiple statements between { }.
>> root [0]  TPostScript *ps = new TPostScript("test.ps");
>> > *** Break *** segmentation violation
>> Root >
>> ---------------------
>> > What's wrong?
>> > Best regards,
>> > Thomas
>> 
> 



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:42 MET