Recent

Author Topic: [SOLVED] Porting Windows project to macOS  (Read 2229 times)

ling

  • New Member
  • *
  • Posts: 14
[SOLVED] Porting Windows project to macOS
« on: November 19, 2020, 06:13:49 am »
I'm trying to port a Windows project to macOS, compilation is ok. The problem happens during the application run, if the second form show with "ShowModal", the application will crash, the message shows:
Quote
Project test.app raised exception class 'Debugger stopped with reason: signal SIGABRT'

Then I found this article: https://wiki.freepascal.org/Cocoa_Internals/Application
Quote
Clogging with Dialogs
There's an issue with a clogged sync processing. If there are two messages sent to the main thread, where both are causing a modal window to be shown. (i.e. an error message). Then if the second one arrives, while the first one is still showing the modal window, the application terminates.

but there is no solution provided for this problem. I'm stuck with it for a couple of days, is there any way to avoid this problem?

I am using Lazarus 2.0.6 with FPC 3.0.4 on Catalina 10.15.17.
« Last Edit: March 16, 2021, 03:13:42 am by ling »

wp

  • Hero Member
  • *****
  • Posts: 11906
Re: Porting Windows project to macOS
« Reply #1 on: November 19, 2020, 09:50:28 am »
Are you sure that the second form exists when you call ShowModal to display it?

Did you create a new project for macOS? This is not necessary, but if you did you maybe forgot to auto-create the second form: "Project options" > "Forms". the left list of "auto-create forms" must contain the name of the forms to be autocreated (the first one being the main form). Likewise, when you look at the project's lpr file it must contain a line "Application.Createform(TForm2, Form2)" (assuming that your second form is named Form2).

If you intentionally did not auto-create the second form (and there are good reasons against auto-cretion) your code must create the form manually before calling its ShowModal:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   if Form2 = nil then
  4.     Application.Createform(TForm2, Form2);
  5.   Form2.ShowModal;
  6. end;

ling

  • New Member
  • *
  • Posts: 14
Re: Porting Windows project to macOS
« Reply #2 on: November 19, 2020, 10:57:23 am »
Yes, I create the form manually before calling ShowModal, the project works fine on Windows.

wp

  • Hero Member
  • *****
  • Posts: 11906
Re: Porting Windows project to macOS
« Reply #3 on: November 19, 2020, 12:02:47 pm »
What is Form2 doing? Is there any Windows-specific stuff in there? Does the crash also happen when you temporarily add another, empty, form to the project and open this one instead of Form2?

ling

  • New Member
  • *
  • Posts: 14
Re: Porting Windows project to macOS
« Reply #4 on: November 20, 2020, 08:36:01 am »
Form 2 is used to collect the information from the user, there are only a few TEdit and a few TButton in it, the information is a prerequisite for the next step. There is no Windows-specific code, btw, the project also works fine on Linux (Mint 17 and RedHat 5.5).

I tried to create an empty form and call ShowModal, it still crashed, but I found MessageDlg works correctly, I have no ideals what is wrong with it.  :(

balazsszekely

  • Guest
Re: Porting Windows project to macOS
« Reply #5 on: November 20, 2020, 09:57:50 am »
@ling
I assume you're using the latest version of lazarus, installed with fpcupdeluxe. If not, please try lazarus trunk, a lot of improvements has been done lately. 
If the issue is still present, then you most likely found a bug and it should be reported in the bugrtracker. As a quick workaround, you can use Show instead of ShowModal and disable the main form:
Code: Pascal  [Select][+][-]
  1. procedure TMainForm.Button1Click(Sender: TObject);
  2. begin
  3.   {$ifdef LCLCocoa}
  4.    MainForm.Enabled := False;
  5.    ModalForm.FormStyle := fsStayOnTop;
  6.    ModalForm.Show;
  7.   {$else}
  8.    ModalForm := TModalForm.Create(nil)
  9.    try
  10.      ModalForm.ShowModal;
  11.    finally
  12.      ModalFrom.Free;
  13.    end;
  14.   {$endif}
  15. end;

When you close the modal form(OnClose event):
Code: Pascal  [Select][+][-]
  1. procedure TModalForm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  2. begin
  3.   {$ifdef LCLCarbon}
  4.   MainForm.Enabled := True;
  5.   CloseAction := caFree;
  6.   {$endif}
  7. end;
  8.  

wp

  • Hero Member
  • *****
  • Posts: 11906
Re: Porting Windows project to macOS
« Reply #6 on: November 20, 2020, 10:33:02 am »
I tested the attached very simple project on a VM with macOS 10.14 and Laz trunk (rather old) / FPC 3.04, and the second form opens without any issues.

Please check this demo with your installation. If it does not work there is a serious issue in macOS support (which I don't believe). If it does work you will have to further study what's wrong. Not being a mac specialist, I could imagine that the order of events might be different on macOS. So: do you have any event handlers attached to both MainForm and Form2? Set breakpoints and try to find out whether object instances are still nil when the event handlers are called.

ling

  • New Member
  • *
  • Posts: 14
Re: Porting Windows project to macOS
« Reply #7 on: December 10, 2020, 11:30:07 am »
@GetMem @wp

Sorry for the late update.
I tested the demo code, it works fine in my environment. Then I thought it could be some initialization thing causes this error.
It is a big project, there are around 1000 units in this project. I tried to simplify the project to figure out what is happened. Finally, I found there is a form that inherits from an interface class, and the form was created in the initialization section of its unit, I postponed the creation time until Application.Initialization, the program works.

Thanks for your suggestion, I will keep updating if I found anything new.

 

TinyPortal © 2005-2018