Recent

Author Topic: [SOLVED] EasyLazFreeType, Memory Load on drawing any charachter....  (Read 1925 times)

ϻαϻɾΣɀО

  • New Member
  • *
  • Posts: 48
  • MaMrEzO
Hi,
Just for note, I`m actively working on fpGUI base on BGRABitma.
After some day of starting, Today just checked for memory usage and comparing it with fpGUI with native canvas!
WOW  :o on any invalidating of form, memory increase a lot(about 0.5 MB).
And also I have a problem already, That App hangs on close!
Today I  find out why! 8-)

On the EasyLazFreeType(Managing glyphs for drawing Text independently :-X) unit any glyph will add to the AVL_Tree every time! Because of the developer of this Component forgot to set OnCompare of the TAvlTree. This event enables AVLTree to compare and put the new Item on the right position on the tree, So after FindGlyph will work.
I did it, Memory loading gone, Hangs on close gone  8-)...

My Changes:
Code: Pascal  [Select]
  1.   // ~/lazarus/components/lazutils/easylazfreetype.pas line1441
  2. constructor TFreeTypeFont.Create;
  3. begin
  4.   EnsureFreeTypeInitialized;
  5.   FFaceLoaded := false;
  6.   FFaceItem := nil;
  7.   FInstanceCreated := false;
  8.   FCharmapOk := false;
  9.   FPointSize := 10;
  10.   FDPI := 96;
  11.   FGlyphTable := TAvlTree.Create;
  12.   FGlyphTable.OnCompare := @GlyphTableOnCompare;   //What need it is...
  13.  

And the GlyphTableOnCompare function:
Code: Pascal  [Select]
  1. function GlyphTableOnCompare(Item1, Item2: Pointer): Integer;
  2. begin
  3.   if TFreeTypeGlyph(Item1).Index = TFreeTypeGlyph(Item2).Index then
  4.     Result := 0
  5.   else if TFreeTypeGlyph(Item1).Index > TFreeTypeGlyph(Item2).Index then
  6.     Result := 1
  7.   else if TFreeTypeGlyph(Item1).Index < TFreeTypeGlyph(Item2).Index then
  8.     Result := -1;
  9. end;  
  10.  

I did it, But for my knowledge, How I can report these kinds of  [improvment/currections]?
« Last Edit: May 25, 2019, 02:14:57 pm by ϻαϻɾΣɀО »
Debio-Sql is a new brand of GUI Database tool for the Firebird RDBMS.
http://debio-sql.ariaian.com/

valdir.marcos

  • Hero Member
  • *****
  • Posts: 795
Re: EasyLazFreeType, Memory Load on drawing any charachter....
« Reply #1 on: May 23, 2019, 07:04:15 pm »
Hi,
Just for note, I`m actively working on fpGUI base on BGRABitma.
After some day of starting, Today just checked for memory usage and comparing it with fpGUI with native canvas!
WOW  :o on any invalidating of form, memory increase a lot(about 0.5 MB).
And also I have a problem already, That App hangs on close!
Today I  find out why! 8-)

On the EasyLazFreeType(Managing glyphs for drawing Text independently :-X) unit any glyph will add to the AVL_Tree every time! Because of the developer of this Component forgot to set OnCompare of the TAvlTree. This event enables AVLTree to compare and put the new Item on the right position on the tree, So after FindGlyph will work.
I did it, Memory loading gone, Hangs on close gone  8-)...

My Changes:
Code: Pascal  [Select]
  1.   // ~/lazarus/components/lazutils/easylazfreetype.pas line1441
  2. constructor TFreeTypeFont.Create;
  3. begin
  4.   EnsureFreeTypeInitialized;
  5.   FFaceLoaded := false;
  6.   FFaceItem := nil;
  7.   FInstanceCreated := false;
  8.   FCharmapOk := false;
  9.   FPointSize := 10;
  10.   FDPI := 96;
  11.   FGlyphTable := TAvlTree.Create;
  12.   FGlyphTable.OnCompare := @GlyphTableOnCompare;   //What need it is...
  13.  

And the GlyphTableOnCompare function:
Code: Pascal  [Select]
  1. function GlyphTableOnCompare(Item1, Item2: Pointer): Integer;
  2. begin
  3.   if TFreeTypeGlyph(Item1).Index = TFreeTypeGlyph(Item2).Index then
  4.     Result := 0
  5.   else if TFreeTypeGlyph(Item1).Index > TFreeTypeGlyph(Item2).Index then
  6.     Result := 1
  7.   else if TFreeTypeGlyph(Item1).Index < TFreeTypeGlyph(Item2).Index then
  8.     Result := -1;
  9. end;  
  10.  

I did it, But for my knowledge, How I can report these kinds of  [improvment/currections]?
Try to contact Graeme directly:
https://forum.lazarus.freepascal.org/index.php?action=profile;u=40195
http://wiki.lazarus.freepascal.org/fpGUI#Support
https://github.com/graemeg/fpgui/
http://fpgui.sourceforge.net/
https://en.wikipedia.org/wiki/FpGUI

korba812

  • Full Member
  • ***
  • Posts: 104
Re: EasyLazFreeType, Memory Load on drawing any charachter....
« Reply #2 on: May 23, 2019, 08:04:14 pm »
How I can report these kinds of  [improvment/currections]?
You should report it in the bugtracker:
http://bugs.freepascal.org/

Try to contact Graeme directly:
This problem is in "lazutils" package, not fpGui.

valdir.marcos

  • Hero Member
  • *****
  • Posts: 795
Re: EasyLazFreeType, Memory Load on drawing any charachter....
« Reply #3 on: May 23, 2019, 09:54:57 pm »
How I can report these kinds of  [improvment/currections]?
You should report it in the bugtracker:
http://bugs.freepascal.org/

Try to contact Graeme directly:
This problem is in "lazutils" package, not fpGui.
I am sorry, I missed that detail.

jamie

  • Hero Member
  • *****
  • Posts: 1899
Re: EasyLazFreeType, Memory Load on drawing any charachter....
« Reply #4 on: May 24, 2019, 03:22:25 am »
How quaint that just happen to be missing, considering there was already an OnCompare event built into it.

I just find it HARDDDDDDDDDDDDDDD to believe!
  >:D

ϻαϻɾΣɀО

  • New Member
  • *
  • Posts: 48
  • MaMrEzO
Re: EasyLazFreeType, Memory Load on drawing any charachter....
« Reply #5 on: May 24, 2019, 09:52:03 am »
How quaint that just happen to be missing, considering there was already an OnCompare event built into it.

I just find it HARDDDDDDDDDDDDDDD to believe!
  >:D

WOW, builtin compare? What compared? And how builtin compare know our strange struct?
OnCompare enable the AVLTree to find out how to compare our structure! When add or find an object to the tree.
Of course, there was a FindGlyphNode function implemented based on AVLTree logic, But it not logical when the AVLTree sorted the objects based on its logic compare and sort  ;D
Debio-Sql is a new brand of GUI Database tool for the Firebird RDBMS.
http://debio-sql.ariaian.com/

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3616
  • I like bugs.
Re: EasyLazFreeType, Memory Load on drawing any charachter....
« Reply #6 on: May 24, 2019, 06:26:56 pm »
Is there a simple way to reproduce the problem in EasyLazFreeType without using fpGUI or BGRABitmap?

ϻαϻɾΣɀО

  • New Member
  • *
  • Posts: 48
  • MaMrEzO
Re: EasyLazFreeType, Memory Load on drawing any charachter....
« Reply #7 on: May 24, 2019, 06:49:57 pm »
Is there a simple way to reproduce the problem in EasyLazFreeType without using fpGUI or BGRABitmap?
Sorry, Currently I don't know any way to use EasyLazFreeType, Except you mentioned.
Debio-Sql is a new brand of GUI Database tool for the Firebird RDBMS.
http://debio-sql.ariaian.com/

ϻαϻɾΣɀО

  • New Member
  • *
  • Posts: 48
  • MaMrEzO
Re: EasyLazFreeType, Memory Load on drawing any charachter....
« Reply #8 on: May 24, 2019, 06:54:02 pm »
It seems that there is an example of use that,
~/lazarus/examples/lazfreetype
Debio-Sql is a new brand of GUI Database tool for the Firebird RDBMS.
http://debio-sql.ariaian.com/

wp

  • Hero Member
  • *****
  • Posts: 6142
Re: EasyLazFreeType, Memory Load on drawing any charachter....
« Reply #9 on: May 24, 2019, 07:48:50 pm »
Is there a simple way to reproduce the problem in EasyLazFreeType without using fpGUI or BGRABitmap?
I did not look into the details of this discussion, but I think the problem should be seen also with TAChart in the demo "savedemo" (folder "components/tachart/demo/save" of the standard Lazarus installation) after clicking on "Save as SVG" because the SVGDrawer uses LazFreeType. This demo requires only a standard Lazarus installation.

ϻαϻɾΣɀО, can you verify that this bug occurs in this demo, too?
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

ϻαϻɾΣɀО

  • New Member
  • *
  • Posts: 48
  • MaMrEzO
Re: EasyLazFreeType, Memory Load on drawing any charachter....
« Reply #10 on: May 24, 2019, 09:06:27 pm »
Is there a simple way to reproduce the problem in EasyLazFreeType without using fpGUI or BGRABitmap?
I did not look into the details of this discussion, but I think the problem should be seen also with TAChart in the demo "savedemo" (folder "components/tachart/demo/save" of the standard Lazarus installation) after clicking on "Save as SVG" because the SVGDrawer uses LazFreeType. This demo requires only a standard Lazarus installation.

ϻαϻɾΣɀО, can you verify that this bug occurs in this demo, too?

Yes, it doses! Just look at memory increasing on your TaskManager!

Just change the TFreeTypeFont.GetGlyph to :
Code: Pascal  [Select]
  1. function TFreeTypeFont.GetGlyph(Index: integer): TFreeTypeGlyph;
  2. var
  3.   node: TAvlTreeNode;
  4.   lGlyph: TFreeTypeGlyph;
  5. begin
  6.   if not CheckInstance then
  7.   begin
  8.     result := nil;
  9.     exit;
  10.   end;
  11.   node := FindGlyphNode(Index);
  12.   if node = nil then
  13.   begin
  14.     lGlyph := TFreeTypeGlyph.Create(self, Index);
  15.     //Log what Index added to Tree, And Count of Glyphs
  16.     WriteLn(Index, FGlyphTable.Count: 8);
  17.     FGlyphTable.Add(lGlyph);
  18.   end else
  19.     lGlyph := TFreeTypeGlyph(node.Data);
  20.   result := lGlyph;
  21. end;  
  22.  
« Last Edit: May 24, 2019, 10:39:58 pm by JuhaManninen »
Debio-Sql is a new brand of GUI Database tool for the Firebird RDBMS.
http://debio-sql.ariaian.com/

howardpc

  • Hero Member
  • *****
  • Posts: 3097
Re: EasyLazFreeType, Memory Load on drawing any charachter....
« Reply #11 on: May 24, 2019, 09:56:20 pm »
Here the ../tachart/demo/save example produces good .bmp, .png, .jpg and clipboard copies, but bombs with an error when attempting the .svg save.
See attached image for the error.

ϻαϻɾΣɀО

  • New Member
  • *
  • Posts: 48
  • MaMrEzO
Re: EasyLazFreeType, Memory Load on drawing any charachter....
« Reply #12 on: May 24, 2019, 10:13:54 pm »
It`s Seems you guys look in the wrong example, Just try lazfreetypetest example located in "/lazarus/examples/lazfreetype".

For start, you must run it with three font name as parameters!
If the application finds the fonts, Its runs with a simple form that render your chosen fonts by moving mouse on the form.
As you move the mouse cursor on the form, Keep your eyes on memory usage of the app in the TaskManager/KSysGuard/GnomeSysMonitor or whatever you are using.
Debio-Sql is a new brand of GUI Database tool for the Firebird RDBMS.
http://debio-sql.ariaian.com/

wp

  • Hero Member
  • *****
  • Posts: 6142
Re: EasyLazFreeType, Memory Load on drawing any charachter....
« Reply #13 on: May 24, 2019, 10:56:02 pm »
It`s Seems you guys look in the wrong example, Just try lazfreetypetest example located in "/lazarus/examples/lazfreetype".
OK - please note this in the bug report. You cannot expect a developer to install any third party libraries in order to see a bug. That's the background of Juha's request. Always provide a demo (as simple as possible) to show the bug.

Here the ../tachart/demo/save example produces good .bmp, .png, .jpg and clipboard copies, but bombs with an error when attempting the .svg save.
There has been a recent discussion about this (I don't want to search myself, sorry). The essence was that there seem to be some fonts around which cannot be read correctly by EasyFreeType. This particular exception is caught in the demo and appears only in the debugger, not outside the IDE:
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

circular

  • Hero Member
  • *****
  • Posts: 2954
    • Personal webpage
Re: EasyLazFreeType, Memory Load on drawing any charachter....
« Reply #14 on: May 24, 2019, 11:27:03 pm »
Thanks for finding that bug. That's probably my mistake as I wrote this unit.

I remember reading that the AVL tree was buggy so that it was the reason it was acting strangely. Well at least there was some error on my side.

Note: I don't have access to the code so please file a bug report.
« Last Edit: May 24, 2019, 11:34:47 pm by circular »
Conscience is the debugger of the mind