Recent

Author Topic: Why is it your program stops working when two windows OVERLAP?  (Read 4383 times)

Awesome Programmer

  • Sr. Member
  • ****
  • Posts: 479
  • Programming is FUN only when it works :)
    • Cool Technology
Why is it your program stops working when two windows OVERLAP?
« on: February 08, 2018, 04:44:36 pm »
This issue had always been BUGGING me to no avail. All of my programs written in Lazarus IDE has this issue. It doesn't matter which Linux Operating System I run the executable on, they all act the same.

Anytime any two windows of my program overlap on top of each other even just a little bit, all activities in my program COMES TO a COMPLETE STOP. What do I mean by that? I have Ttimer in my program that is supposed to run every second and it STOPS for no apparent reason other than the the fact that two windows are overlapped even though the program is still active and the whole computer system is still running. As soon as I separate the windows away from each other Ttimer starts running again. I can't seem to understand that or why it is doing that.

Can someone please shed some light on this? Thank you.


marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12708
  • FPC developer.
Re: Why is it your program stops working when two windows OVERLAP?
« Reply #1 on: February 08, 2018, 04:48:24 pm »
YOU DON'T provide ANYTHING to TEST, and DON'T even MENTION the WIDGETSET or VERSION you USE!

Handoko

  • Hero Member
  • *****
  • Posts: 5524
  • My goal: build my own game engine using Lazarus
Re: Why is it your program stops working when two windows OVERLAP?
« Reply #2 on: February 08, 2018, 04:51:17 pm »
They always think we have a crystal ball. :D

Awesome Programmer

  • Sr. Member
  • ****
  • Posts: 479
  • Programming is FUN only when it works :)
    • Cool Technology
Re: Why is it your program stops working when two windows OVERLAP?
« Reply #3 on: February 08, 2018, 04:57:26 pm »
YOU DON'T provide ANYTHING to TEST, and DON'T even MENTION the WIDGETSET or VERSION you USE!

All this is done on Linux Operating Systems ONLY ... NO WINDOWS. Probably GTK+. Currently, I am running Lazarus 1.0.12 and fpc 2.6.2.

What I am experiencing seems to happen to windows that has Formpaint event defined or assigned to them.

« Last Edit: February 08, 2018, 05:00:30 pm by Awesome Programmer »

Handoko

  • Hero Member
  • *****
  • Posts: 5524
  • My goal: build my own game engine using Lazarus
Re: Why is it your program stops working when two windows OVERLAP?
« Reply #4 on: February 08, 2018, 05:02:04 pm »
Can anyone tell me where to buy a crystal ball? I would like to purchase one, but can't find it at eBay. I really need it to peek at OP's source code, he is too shy to show it.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Why is it your program stops working when two windows OVERLAP?
« Reply #5 on: February 08, 2018, 05:07:39 pm »
Can anyone tell me where to buy a crystal ball? I would like to purchase one, but can't find it at eBay. I really need it to peek at OP's source code, he is too shy to show it.
they are not for sale and they can not be manufactured, they are passed down from wizard to wizard you have to demonstrate considerable insight to be chosen though and most of the times you end up creating your own before any old timer decide to part with theirs.

As for the problem at hand does the problem exists if the formpaint event is empty? How about if it only calculates the square root of a random number? If not, then your code creates the problem, post the formpaint code (the complete code) here and we will take a look. If you do not want to then comment out every one line at a time until the problem goes way or one paragraph at a time etc.
« Last Edit: February 08, 2018, 05:10:35 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Thaddy

  • Hero Member
  • *****
  • Posts: 18765
  • To Europe: simply sell USA bonds: dollar collapses
Re: Why is it your program stops working when two windows OVERLAP?
« Reply #6 on: February 08, 2018, 05:45:25 pm »
Maybe?
Code: Pascal  [Select][+][-]
  1. procedure TForm2.FormDragOver(Sender, Source: TObject; X, Y: Integer;
  2.   State: TDragState; var Accept: Boolean);
  3. begin
  4.   accept:=true;
  5.   Application.terminate;
  6. end;

 :D :D :D :D %) You never know, do you... O:-) Just kidding: without example code we can't reproduce it except on purpose.
« Last Edit: February 08, 2018, 05:50:22 pm by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

Handoko

  • Hero Member
  • *****
  • Posts: 5524
  • My goal: build my own game engine using Lazarus
Re: Why is it your program stops working when two windows OVERLAP?
« Reply #7 on: February 08, 2018, 06:11:16 pm »
So this is a guessing game?

I like doing debugging but I hate doing it wearing opaque black eyeglass. 8-)
It sounds cool but I can't see.

Lets the game begin.

I wrote a simple test to reproduce the issue the TS said. But I cannot reproduce it on Lazarus 1.8.0 Gtk2 Ubuntu Mate 17.10 64-bit.

Here are my guesses:

1. He forgot to call invalidate, see my code.
2. He used a buggy version of Lazarus 1.0.12.
3. He didn't do things correctly in TTimer.OnTimer event.
4. He didn't do things correctly in TForm.OnPaint event.

So, tell me do I win this game? ;)

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, StdCtrls, ExtCtrls, Unit2;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     Button2: TButton;
  17.     Timer1: TTimer;
  18.     procedure Button1Click(Sender: TObject);
  19.     procedure Button2Click(Sender: TObject);
  20.     procedure FormPaint(Sender: TObject);
  21.     procedure Timer1Timer(Sender: TObject);
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.   PosX: Integer = 350;
  27.  
  28. implementation
  29.  
  30. {$R *.lfm}
  31.  
  32. { TForm1 }
  33.  
  34. procedure TForm1.Timer1Timer(Sender: TObject);
  35. begin
  36.   Form1.Invalidate;
  37. end;
  38.  
  39. procedure TForm1.Button1Click(Sender: TObject);
  40. begin
  41.   Button1.Enabled := False;
  42.   Button2.Visible := True;
  43.   Timer1.Enabled  := True;
  44. end;
  45.  
  46. procedure TForm1.Button2Click(Sender: TObject);
  47. begin
  48.   Button2.Enabled := False;
  49.   Form2.Show;
  50. end;
  51.  
  52. procedure TForm1.FormPaint(Sender: TObject);
  53. begin
  54.   Canvas.Brush.Color := clForm;
  55.   Canvas.Clear;
  56.   Canvas.Rectangle(PosX, 130, PosX + 20, 150);
  57.   Dec(PosX, 8);
  58.   if (PosX < -30) then PosX := Width + 50;
  59. end;
  60.  
  61. end.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Why is it your program stops working when two windows OVERLAP?
« Reply #8 on: February 08, 2018, 06:27:37 pm »
Oh goodie guessing.
1) he uses invalidate to often
2) he uses application.processmessages.
3) he disables the timer and never enables it again.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Awesome Programmer

  • Sr. Member
  • ****
  • Posts: 479
  • Programming is FUN only when it works :)
    • Cool Technology
Re: Why is it your program stops working when two windows OVERLAP?
« Reply #9 on: February 08, 2018, 07:43:06 pm »
here is my formpaint event

Code: Pascal  [Select][+][-]
  1. procedure TviewFrm.FormPaint(Sender: TObject);
  2. var
  3.   DC,MemDC:HDC;
  4.   MemBitmap,OldBitmap:HBITMAP;
  5. begin
  6.      DC := Canvas.Handle;
  7.      MemBitmap := CreateCompatibleBitmap(DC,ClientRect.Right,ClientRect.Bottom);
  8.      MemDC := CreateCompatibleDC(0);
  9.      OldBitmap := SelectObject(MemDC,MemBitmap);
  10.      Canvas.Handle := MemDC;
  11.      try
  12.         Canvas.Brush.Color := Color;
  13.         Canvas.FillRect(Rect(0,0,ClientWidth,ClientHeight));
  14.         Canvas.Lock;
  15.         myObjects.Draw;
  16.         BitBlt(DC,0,0,ClientRect.Right,ClientRect.Bottom,MemDC,0,0,SRCCOPY);
  17.         Canvas.Unlock;
  18.      finally
  19.             Canvas.Handle := DC;
  20.             SelectObject(MemDC,OldBitmap);
  21.             DeleteDC(MemDC);
  22.             DeleteObject(MemBitmap);
  23.      end;
  24. end;
  25.  

Handoko

  • Hero Member
  • *****
  • Posts: 5524
  • My goal: build my own game engine using Lazarus
Re: Why is it your program stops working when two windows OVERLAP?
« Reply #10 on: February 08, 2018, 07:49:16 pm »
Maybe you can try:

- Move the Canvas.UnLock to the finally section
- Call Form.Invalidate at the end of TTimer.OnTimer
- Call Application.ProcessMessages in the TTimer.OnTimer

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Why is it your program stops working when two windows OVERLAP?
« Reply #11 on: February 08, 2018, 08:27:28 pm »
here is my formpaint event

Code: Pascal  [Select][+][-]
  1. procedure TviewFrm.FormPaint(Sender: TObject);
  2. var
  3.   DC,MemDC:HDC;
  4.   MemBitmap,OldBitmap:HBITMAP;
  5. begin
  6.      DC := Canvas.Handle;
  7.      MemBitmap := CreateCompatibleBitmap(DC,ClientRect.Right,ClientRect.Bottom);
  8.      MemDC := CreateCompatibleDC(0);
  9.      OldBitmap := SelectObject(MemDC,MemBitmap);
  10.      Canvas.Handle := MemDC;
  11.      try
  12.         Canvas.Brush.Color := Color;
  13.         Canvas.FillRect(Rect(0,0,ClientWidth,ClientHeight));
  14.         Canvas.Lock;
  15.         myObjects.Draw;
  16.         BitBlt(DC,0,0,ClientRect.Right,ClientRect.Bottom,MemDC,0,0,SRCCOPY);
  17.         Canvas.Unlock;
  18.      finally
  19.             Canvas.Handle := DC;
  20.             SelectObject(MemDC,OldBitmap);
  21.             DeleteDC(MemDC);
  22.             DeleteObject(MemBitmap);
  23.      end;
  24. end;
  25.  
1) keep the canvas locked for the entirety of the paint event not only when your objects are drawn.
2)the form is most likely already double buffered your code makes it triple buffered drop the code for compatible dc code and use the form.doublebuffered property if you need to make sure.
3) myobjects.draw; is a black box so it raises a flag for me.
4) never use application.processMessages there are exceptions to that rule, if you do not know what they are, you do not need to use it.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Why is it your program stops working when two windows OVERLAP?
« Reply #12 on: February 08, 2018, 09:39:40 pm »
Currently, I am running Lazarus 1.0.12 and fpc 2.6.2.

Are these a bit outdated?

 

TinyPortal © 2005-2018