Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2018-01

GTK2/X Appcrash when TPen.Pattern has invalid value

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Alexander Hofmann

Dear all,

I spend some time debugging a programming error (read: misinterpretation of available documentation) and though I should share my findings...

I wanted to have a TChart series drawn with a dashed line, the pen-style "psDashed" had two short dashes for my eyes, so I used "psPattern" and set the Pen-Pattern as such:

const
  Pattern:array [0..7] of longint=(1, 1, 1, 1, 0, 0, 0, 0)

This is wrong of course; however reading some google I thought that each array element in the TPenPattern array describes one pixel. The problem now was, that Qt produces quite reasonable results: a 4-pixel dashed line. Also GTK2 did the job - if the line was drawn _outside_ any Paint-Message.

In that case (e.g. when actually setting this as a Pen-Pattern for a Chart series), the X-Function 58 (SetDashes) produced the Errorcode 2 (Out of range) and the Program ended directly at the 1st Paint-Event - leaving Lazarus and GDB in the wild with no backtrace or alike.

Of course it works now with the Pattern

const
  Pattern:array [0..1] of longint=(4, 4)

But: I think that, if this is the correct way to do it, and the value "0" for any portion of the pattern is indeed not allowed (as stated in the X-Documentation e.g. here:
https://www.x.org/releases/X11R7.7/doc/xproto/x11protocol.html#requests:SetDashes), shouldn't TPen.SetPattern raise an exception when an invalid pattern is given?

I don't know about other OSes / Widgestsets, if there are the same "rules".

I could try to file a bugreport / try to provide a patch; but maybe it's enough to cite the X-Docs somewhere in the Lazarus-Documentation? What do you think?

Regards,

Alex

Reply by email

Marc Weustink
to Alexander Hofmann
Alexander Hofmann wrote 37 lines
Dear all, I spend some time debugging a programming error (read: misinterpretation of available documentation) and though I should share my findings... I wanted to have a TChart series drawn with a dashed line, the pen-style "psDashed" had two short dashes for my eyes, so I used "psPattern" and set the Pen-Pattern as such: const   Pattern:array [0..7] of longint=(1, 1, 1, 1, 0, 0, 0, 0) This is wrong of course; however reading some google I thought that each array element in the TPenPattern array describes one pixel. The problem now was, that Qt produces quite reasonable results: a 4-pixel dashed line. Also GTK2 did the job - if the line was drawn _outside_ any Paint-Message. In that case (e.g. when actually setting this as a Pen-Pattern for a Chart series), the X-Function 58 (SetDashes) produced the Errorcode 2 (Out of range) and the Program ended directly at the 1st Paint-Event - leaving Lazarus and GDB in the wild with no backtrace or alike. Of course it works now with the Pattern const   Pattern:array [0..1] of longint=(4, 4) But: I think that, if this is the correct way to do it, and the value "0" for any portion of the pattern is indeed not allowed (as stated in the X-Documentation e.g. here: https://www.x.org/releases/X11R7.7/doc/xproto/x11protocol.html#requests:SetDashes), shouldn't TPen.SetPattern raise an exception when an invalid pattern is given?

Don't think so. The gtk implementation should have checked this and probably skip the 0

I don't know about other OSes / Widgestsets, if there are the same "rules".

Imo the QT implementation should be adapted to behave the same. Wat does Delphi in this case?

I could try to file a bugreport / try to provide a patch; but maybe it's enough to cite the X-Docs somewhere in the Lazarus-Documentation? What do you think?

We shouldn't "copy"the x behaviour, but behave the same as Delphi.

Marc

Reply by email

Alexander Hofmann
to Marc Weustink

Hi,

Marc Weustink wrote
Imo the QT implementation should be adapted to behave the same. Wat does Delphi in this case?

Thank's for your reply.
I only have an old Delphi 7 version here - they all don't have the Pattern option for TPen. When done manually, the ExtCreatePen function of the Windows GDI also expects an array with the length(s) of individual strokes in the pattern (see
https://msdn.microsoft.com/en-us/library/windows/desktop/dd162705(v=vs.85).aspx ), so I would expect newer Delphi versions to implement it that way (same as on X).

Of course this is still MY failure, not any of the LCL...

Best regards,
Alex

Reply by email