avk959 / LGenerics

Generic algorithms and data structures for Lazarus/Free Pascal
Apache License 2.0
113 stars 16 forks source link

Linux - lgAvlTree Enumerator Error #12

Closed uvwx413 closed 1 year ago

uvwx413 commented 1 year ago

on MX-Linux, Mint Linux, code like here will raise invalid pointer error, but on Windows 7, everything go right and if I switch back to LGenerics_054, non error

// my test code

type

   TWordSetSpec = specialize TGLiteTreeSet<string, string>;

var 
  ws: TWordSetSpec;
begin
  ws.Add('S1');
  ws.Add('M2');
  ws.Add('K3');
  for s in ws do
      Memo1.Append(s);     // first 'K3' , Okay;   but Next, Raise error at lgAvlTree line 2666
end;

// the lgAvlTree .pas

function TGLiteAvlTree.TEnumerator.MoveNext: Boolean;
var
  NextNode: SizeInt = 0;
begin
  if FCurrNode <> 0 then
    NextNode := FTree^.Successor(FCurrNode)    //  this line(2666),  FTree INVALID pointer error
else
  ...

Compiler: FPC 3.2.2 Lazarus: 2.2.6

uvwx413 commented 1 year ago

Here is another test code

program wsTest;

uses SysUtils,
  {$DEFINE LGENERICS_054}
  {$IFDEF LGENERICS_054} LGTreeSet, LGHashSet;
  {$ELSE}    lgTreeSet, lgHashSet;
  {$ENDIF}
type
  TWordSet = specialize TGLiteTreeSet<string, string>;

var
  wSet: TWordSet;
  w: string;
  i: integer;
begin
  Writeln('And 10 words to wSet');
  Randomize;
  for i:=1 to 10 do
  begin
    w := 'Random_' + IntToStr(Random(100));
    wSet.Add( w );
    Writeln( w );
  end;

  Writeln('Words in wSet:');
  for w in wSet do   // LGenerics_master: raise exception on lgAvlTree.pas line 2666
    Writeln( w );
  Writeln('END.');
  Readln;
end.

Is it memory overwrite? ( initialization has done at Line 2624 : FNodes[Result].ClearLinks; )

avk959 commented 1 year ago

Thanks for the feedback. It seems that the problem was initialization of TGLiteTreeSet enumerators. Looks like this is fixed now?

uvwx413 commented 1 year ago

Thank you very much! LGenerics is an EXCELENT library!