### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: Problems with External: SIGSEV  (Read 2809 times)

#### stab

• Full Member
• Posts: 197
##### Problems with External: SIGSEV
« on: January 31, 2018, 11:17:40 pm »
I'm trying to use Angus Johnsons Clipper routines to offset polygons but
get External: SIGSEV in the constructor of TClipperOffset object:

constructor TClipperOffset.Create(
MiterLimit: Double = 2;
ArcTolerance: Double = def_arc_tolerance);
begin
inherited Create;
FPolyNodes := TPolyNode.Create; <-- External: SIGSEV
FLowest.X := -1;
FMiterLimit := MiterLimit;
FArcTolerance := ArcTolerance;
end;

TPolyNode = class
private
FPath    : TPath;
FParent  : TPolyNode;
FIndex   : Integer;
FCount   : Integer;
FBuffLen : Integer;
FIsOpen  : Boolean;
FChilds  : TArrayOfPolyNode;
FJoinType: TJoinType; //used by ClipperOffset only
FEndType : TEndType;  //used by ClipperOffset only
function  GetChild(Index: Integer): TPolyNode;
function  IsHoleNode: boolean;
function  GetNextSiblingUp: TPolyNode;
public
function  GetNext: TPolyNode;
property  Childs[index: Integer]: TPolyNode read GetChild;
end;

As of my understanding TPolyNode is implicitely of type TObject and would
be created as such.

What can cause the problems?

Windows 10 64 bits
Lazarus v.1.8.0
FPC 3.0.4

Regards
stab

#### jamie

• Hero Member
• Posts: 4841
##### Re: Problems with External: SIGSEV
« Reply #1 on: January 31, 2018, 11:31:54 pm »

TPolyNode = Class(Tobject)

...

end;
At one time I did have an strange issue where I needed to specify TObject for the base, I just can't
remember what the real cause was.\

Maybe I remember now.., you may need to put in a base Constructor Create to start off with...

« Last Edit: January 31, 2018, 11:33:26 pm by jamie »
The only true wisdom is knowing you know nothing

#### Martin_fr

• Hero Member
• Posts: 7404
• Debugger - SynEdit - and more
##### Re: Problems with External: SIGSEV
« Reply #2 on: January 31, 2018, 11:42:13 pm »
1) Run in the debugger.

Check the stacktrace in the debugger, maybe the exception happens somewhere higher up.

Check "self" has a value. It should since you are in a constructor.
Though if you do this
Code: Pascal  [Select][+][-]
1. var foo: TClipperOffset;
2. //...
3. foo := nil; // or random value
4. foo.create();

Then instead of creating an instance you may just be calling the constructor with self=nil (or random). Then accessing FPolyNodes  will crash.

2) Run with -gh -gt
set env variable
HEAPTRC="keepreleased"

You may have memory corruption anywhere else. Then the crash just happens here, because it finally tripped over the memory that was corrupted some where else.

#### wp

• Hero Member
• Posts: 8749
##### Re: Problems with External: SIGSEV
« Reply #3 on: February 01, 2018, 12:34:59 am »
I tried to compile the Delphi clipper_demo with Laz 1.8/fpc 3.04 (32 bit) on Win 10/64 bit, and did not see any such issues. Some files required a {\$mode Delphi} directive, I had to remove the unknown properties Margins.* from the form file. And then, of course, the standard changes for using a Delphi project within Lazarus: rename the project file to .lpr, rename form file from dfm to lfm, add package graphics32 to project requirements, add main.pas to project, in main.pas change the directive {\$R *.dfm} to {\$R *.lfm}, add "Interfaces" to the project unit. I think that was all.

I am attaching the Lazarus project.

P.S.
I should mentioned that I installed graphics32 via Online-Package-Manager.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

#### stab

• Full Member
• Posts: 197
##### Re: Problems with External: SIGSEV
« Reply #4 on: February 02, 2018, 11:12:52 am »
Thank you all for your tips!
I'll try to use them to solve my problems.

#### marcio2003

• Jr. Member
• Posts: 59
##### Re: Problems with External: SIGSEV
« Reply #5 on: August 03, 2021, 01:10:36 am »
Hi,

A long time ago I made my own algorithm to solve this, you enter a point and you get the closed polygon that surrounds it.

Sometimes there will be no closed polygon surrounding the point, so the answer will be an empty polygon.

Only two results: one closed polygon or one empty polygon.

It works with dynamic array and initially with a large number of nodes.

Todo: detect islands within the polygon.

It might need to be optimized for better performance to work with large numbers of nodes, but it works.

It was not an easy task.

« Last Edit: August 03, 2021, 01:19:15 am by marcio2003 »
Lazarus 2.0.10 Windows 10 64bits