Recent

Author Topic: Hang  (Read 980 times)

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 392
Hang
« on: April 08, 2026, 09:52:19 pm »
So, this is executed repeatedly, not necessary to go to 10000 loops, can be broke. And executed again and again by click.
No memory loos - checking in task manager - +/- 23000 Kb
But suddenly it stops working, stops drawing in the middle of thing.
UI does not look completely frozen, just does not draw anything to Paintbox anymore.

Any clue ? Problem in TFloatPointArray or PaintBox ?

like +/-:
 
Code: Pascal  [Select][+][-]
  1. procedure TForm2.Button30Click(Sender: TObject);  
  2. type TFloatPointArray = array of TFloatPoint;
  3. var
  4.    FPA: TFloatPointArray;                            
  5. begin
  6.  for k := 0 to 10000 do
  7.  begin
  8.  
  9.  
  10.     application.ProcessMessages;
  11.  
  12.     Setlength(FPA,0);
  13.  
  14.     // fill FPA .....
  15.  
  16.    
  17.  
  18.    form1.PaintBox1.Repaint;
  19.    // print out result from FPA to form1.PaintBox1 - draw lines between points
  20.  end;
  21.  
  22. end;
  23.  
« Last Edit: April 08, 2026, 09:56:26 pm by BubikolRamios »
lazarus 3.2-fpc-3.2.2-win32/win64

Bart

  • Hero Member
  • *****
  • Posts: 5712
    • Bart en Mariska's Webstek
Re: Hang
« Reply #1 on: April 08, 2026, 11:04:37 pm »
IIRC you should only use the PaintBox's OnPaint for drawing.

Bart

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12765
  • FPC developer.
Re: Hang
« Reply #2 on: April 08, 2026, 11:23:39 pm »
.... and call Paintbox.invalidate to trigger it to happen on typically the next Application.processmessages.

Handoko

  • Hero Member
  • *****
  • Posts: 5526
  • My goal: build my own game engine using Lazarus
Re: Hang
« Reply #3 on: April 09, 2026, 04:20:09 am »
@BubikolRamios

Your code has several flaws, as what already mentioned by Bart and Marcov. And there also some other problems.

Application.ProcessMessages is an expensive command, calling it inside a big for-next loop is a big no. You can see my example code how I can improve the performance several folds simply by reducing the amount of calling Application.ProcessMessages in the code in the link below:
https://forum.lazarus.freepascal.org/index.php/topic,43806.msg307101.html#msg307101

Even if you solve the performance issue, you are very likely to have flickering problem. You can see my explanation for solving flicking problem in the post below:
https://forum.lazarus.freepascal.org/index.php/topic,38136.msg263143.html#msg263143

Additionally, I should tell you: use a good graphics library if you want to do graphics in Lazarus. Lazarus default graphics functions (TBitmap, TCanvas, etc) is not optimized for performance, it is for cross-platform compatibility. If you want to do graphics without using third party library, you will have better luck using FreeBASIC.

Khrys

  • Sr. Member
  • ****
  • Posts: 411
Re: Hang
« Reply #4 on: April 09, 2026, 07:02:56 am »
No memory loos - checking in task manager - +/- 23000 Kb

Did you also check the CPU usage in the task manager? I'm willing to bet it was at 100% during that loop (on a single core).

What is this code supposed to achieve, anyway? Show an animation?

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 392
Re: Hang
« Reply #5 on: April 09, 2026, 04:14:43 pm »
goes around normally, stops at random point
lazarus 3.2-fpc-3.2.2-win32/win64

Handoko

  • Hero Member
  • *****
  • Posts: 5526
  • My goal: build my own game engine using Lazarus
Re: Hang
« Reply #6 on: April 09, 2026, 05:42:39 pm »
That is an interesting project.

You can post the source code here, many users here may able to help you fix the issue. Or if you want, you can privately send it to me, I like solving graphics related problems. But be patient, I'm a bit busy at the moment.

 

TinyPortal © 2005-2018