* * *

Author Topic: [SOLVED] TChart with Minors bug (unfreed memory blocks)!?  (Read 1887 times)

eaea

  • Newbie
  • Posts: 2
[SOLVED] TChart with Minors bug (unfreed memory blocks)!?
« on: May 04, 2018, 11:24:03 pm »
Hello to all!

This is my first post here (and one of my few post ever in my life to a forum), so please be patient with me   :)

When Minors are added to a TChartAxis of a TChartAxisList of a TChart and some Point are added to the charts' series (here: Chart1LineSeries1) and the application is closed then there are unfreed memory blocks reported.

I have tried to manually clear, free, destroy the series and the chart in various order, with no effect.

In the attachment's zip-file is a minimalistic project of few lines, which demonstrates this.

Lazarus version: 1.8.2 (2018-03-30)
FPC version: 3.0.4
SVN revision: 57369
OS: Windows 10, x86 64 bit

Ether this is a bug or I'm doing something wrong...

Greetings

To the admin: I wrote this post some minutes ago, but i cannot find it anymore - maybe its lost. Please delete the previous post.
« Last Edit: May 10, 2018, 11:23:26 pm by eaea »

wp

  • Hero Member
  • *****
  • Posts: 4988
Re: TChart with Minors bug (unfreed memory blocks)!?
« Reply #1 on: May 05, 2018, 12:02:46 am »
I can confirm the issue, I will have a look...
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

wp

  • Hero Member
  • *****
  • Posts: 4988
Re: TChart with Minors bug (unfreed memory blocks)!?
« Reply #2 on: May 06, 2018, 11:13:24 pm »
Thank you for waiting. Fixed in r57796, Lazarus trunk. back-porting to the next fixes release is requested.

Since you use version 1.8.2 you must appy the patch manually if you want to have the fix immediately:
  • Open file tachartaxis.pas (from (lazarus)/components/tachart)
  • Find the procedure "DrawMinors", it is nested within TChartAxis.Draw and should begin near line 464.
  • Replace the entire "DrawMinors" procedure by the following code:
Code: Pascal  [Select]
  1.   procedure DrawMinors(AFixedCoord: Integer; AMin, AMax: Double);
  2.   const
  3.     EPS = 1e-6;
  4.   var
  5.     j: Integer;
  6.     minorMarks: TChartValueTextArray;
  7.     m: TChartValueText;
  8.   begin
  9.     if IsNan(AMin) or (AMin = AMax) then exit;
  10.     for j := 0 to Minors.Count - 1 do begin
  11.       minorMarks := Minors[j].GetMarkValues(AMin, AMax);
  12.       if minorMarks = nil then continue;
  13.       with FHelper.Clone do
  14.         try
  15.           FAxis := Minors[j];
  16.           // Only draw minor marks strictly inside the major mark interval.
  17.           FValueMin := Max(FAxisTransf(AMin), FValueMin);
  18.           FValueMax := Min(FAxisTransf(AMax), FValueMax);
  19.           if FValueMax <= FValueMin then
  20.             continue;
  21.           ExpandRange(FValueMin, FValueMax, -EPS);
  22.           FClipRangeDelta := 1;
  23.           try
  24.             BeginDrawing;
  25.             for m in minorMarks do
  26.               DrawMark(AFixedCoord, FHelper.FAxisTransf(m.FValue), m.FText);
  27.           finally
  28.             EndDrawing;
  29.           end;
  30.         finally
  31.           Free;
  32.         end;
  33.     end;
  34.   end;
  • Save and recompile Lazarus by "Tools" > "Build Lazarus with profile...". This wil take a while. When the process is finished Lazarus will restart with the fix included.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

eaea

  • Newbie
  • Posts: 2
[SOLVED] TChart with Minors bug (unfreed memory blocks)!?
« Reply #3 on: May 10, 2018, 10:15:16 pm »
Hello

... this works great - thank you very much!

Greetings


(How to mark a topic solved???)

howardpc

  • Hero Member
  • *****
  • Posts: 2781
Re: TChart with Minors bug (unfreed memory blocks)!?
« Reply #4 on: May 10, 2018, 10:18:59 pm »
You (the topic originator) are able to edit the topic Subject to include "SOLVED" or some such.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus