X11 crash on TH1D::Draw with root_v4.00/08, cygwin1.5.11

I have the latest cygwin (1.5.11) with gcc3.3.3 and the latest version of X installed and running on Windows XP. I built root_v4.00/08 from source. I startx, run root, and everything seems to work fine. Except this: if I make a TH1D with the default constructor and set the binning to have more than 23607 bins, Xwindows will crash when I call TH1D::Draw(). For example:

root [0] TH1D h
root [1] h.SetBins(50000, 0, 1)
root [2] h.Draw()

… X crashes!! It’s fine if the first argument to SetBins is <= 23607, and crashes if it is >= 23608. I don’t know what could be special about that number. However, the following works just fine:

root[0] TH1D h(“h”, “h”, 50000, 0, 1)
root[1] h.Draw()
root[2] h.SetBins(100000, 0, 1)
root[3] h.Draw()

Any ideas what could be causing this instability?

Thank You,
Jason Detwiler

I cannot reproduce this problem. However, I do not have the latest cygwin.

Rene

Hi Jason,
I can reproduce it. XWin core dumps; it seems there’s a problem with the current X server or with cygwin itself. You might want to send an email to the cygwin xfree mailing list at cygwin-xfree@cygwin.com. There have been other reports of XWin dumping a core [sources.redhat.com].
Axel.

Hi,
I tracked it down. The problem is that h.Draw draws a polygon with a lot of points. XDrawPolygon (well, one of its worker ants) allocates memory on the stack for the coords of all these points, using alloca. alloca’s behaviour is undefined if the available stack space is not big enough (it’s big enough for the polygon representing 23607 bins, but not for the 23608 bins one). On cygwin “undefined” apparently means it SIGSEGVs. You can get a similar behaviour (watch it, X is pretty unhappy afterwards, but at least it’s still alive) using these lines on linux:

[code]TH1D h
h.SetBins(5000000, 0, 1)
h.Draw()
TCanvas::MakeDefCanvas: created default TCanvas with name c1
Error in : fatal X11 error (connection to server lost?!)

**** Save data and exit application ****
[/code]
It’s not a problem with TH1D’s memory usage for its fArray - it’s an X11 problem. Only solutions I see: use less bins, or tell the x11 cygwin guys (see http://x.cygwin.com) that you think you should be able to draw a polygon with 100000 (or something) points. Maybe one of the ROOT graphics experts has an idea how to prevent the histpainter from drawing deadly polygons. After all, we’ll have to wait a bit for displays with a resolution big enough to separate 23607 bins…
Axel.