Recent

Author Topic: Deadlock with ShowModal and CanClose on OSX  (Read 4342 times)

agorka

  • New Member
  • *
  • Posts: 25
Deadlock with ShowModal and CanClose on OSX
« on: May 21, 2016, 09:57:16 pm »
Hello!

I've run into some problem.
My OSX program has quit confirmation.
When I display a modal window, main menu gets disabled.
But if press Command-Q, it still triggers program close routine and displays quit confirmation.
Problem that it doesn't react to any input, so my program get locked.
Here's the test I made:
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, LclType;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     procedure Button1Click(Sender: TObject);
  17.     procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
  18.     procedure FormCreate(Sender: TObject);
  19.   private
  20.     { private declarations }
  21.   public
  22.     { public declarations }
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.  
  28. implementation
  29.  
  30. {$R *.lfm}
  31.  
  32. { TForm1 }
  33.  
  34. procedure TForm1.FormCreate(Sender: TObject);
  35. Begin
  36. end;
  37.  
  38. procedure TForm1.Button1Click(Sender: TObject);
  39. var
  40.   Dlg : TForm;
  41. begin
  42.   Dlg := TForm.CreateNew(Self);
  43.   Dlg.ShowModal;
  44. end;
  45.  
  46. procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: boolean);
  47. begin
  48.   CanClose:=Application.MessageBox('Are you sure you want to quit?', 'Question', MB_YesNo) = IdYes;
  49. end;
  50.  
  51. end.
  52.  

What would you recommend to fix this?

andydunkel

  • Newbie
  • Posts: 4
Re: Deadlock with ShowModal and CanClose on OSX
« Reply #1 on: July 17, 2016, 06:05:48 pm »
This seems to be a bug in Lazarus 1.6 on OSX.

I am facing a similar issue, when opening a modal dialog:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   Form2.ShowModal;
  4. end;
  5.  

When I open another dialog from Form2, the application hangs:

Code: Pascal  [Select][+][-]
  1. procedure TForm2.Button1Click(Sender: TObject);
  2. begin
  3.   ShowMessage('HelloWorld');
  4. end;

I am unable to close the ShowMessage dialog and the application is no longer responding.

I tested this with Lazarus 1.4, no issues there.

Andy

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Deadlock with ShowModal and CanClose on OSX
« Reply #2 on: July 17, 2016, 06:15:24 pm »
When I open another dialog from Form2, the application hangs:

I believe that's a known bug in 1.6. It should be fixed in trunk, so you're only recourse is to build from trunk.

I agree, it sure does render Lazarus 1.6 and any apps created with it pretty useless.

-Phil

Ondrej Pokorny

  • Full Member
  • ***
  • Posts: 220
Re: Deadlock with ShowModal and CanClose on OSX
« Reply #3 on: July 18, 2016, 08:10:32 pm »
Well it's missing functionality in 1.6 and it hasn't been solved in trunk.

The problem is missing support of PopupParent in Carbon that was solved in 1.0-1.4 with a workaround that caused other bugs. I had to revert this workaround.

See http://mantis.freepascal.org/view.php?id=16883
« Last Edit: July 18, 2016, 08:16:25 pm by ondrejpokorny »

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Deadlock with ShowModal and CanClose on OSX
« Reply #4 on: July 18, 2016, 08:18:02 pm »
The problem is missing support of PopupParent in Carbon that was solved in 1.0-1.4 with a workaround that caused other bugs. I had to revert this workaround.

I'm a little confused on the chronology. You reverted on Feb. 24, but 1.6 was released Feb. 18. Andy is using 1.6. Is that not a 1.6 problem?

Thanks.

-Phil

Ondrej Pokorny

  • Full Member
  • ***
  • Posts: 220
Re: Deadlock with ShowModal and CanClose on OSX
« Reply #5 on: July 18, 2016, 08:59:54 pm »
The problem is missing support of PopupParent in Carbon that was solved in 1.0-1.4 with a workaround that caused other bugs. I had to revert this workaround.

I'm a little confused on the chronology. You reverted on Feb. 24, but 1.6 was released Feb. 18. Andy is using 1.6. Is that not a 1.6 problem?

Oh yes, you are correct, I mixed the things up a little bit. Actually my revert from Feb 24th was the fix for this bug :) It's in 1_6_fixes (that you can use, agorka) and it will be available in 1.6.2.

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Deadlock with ShowModal and CanClose on OSX
« Reply #6 on: July 18, 2016, 09:03:30 pm »
It's in 1_6_fixes (that you can use, agorka) and it will be available in 1.6.2.

Very good.

It appears as though the patch given here should be what Andy needs if he doesn't want to download trunk:

http://mantis.freepascal.org/view.php?id=29694

Thanks.

-Phil

andydunkel

  • Newbie
  • Posts: 4
Re: Deadlock with ShowModal and CanClose on OSX
« Reply #7 on: July 19, 2016, 09:18:51 pm »
Thanks for the help! I applied the patch and rebuild the IDE. Now its working again!  :D

Andy

 

TinyPortal © 2005-2018