Recent

Author Topic: Cocoa Application not working from bundle.  (Read 9468 times)

Josh

  • Hero Member
  • *****
  • Posts: 1271
Cocoa Application not working from bundle.
« on: September 12, 2018, 09:13:03 pm »
Hi

I have an application that runs fine in carbon, and now compiles for x-64 for cocoa.
The application runs if I run the executable direct from Finder,
if I create an application bundle using Lazarus then I do not get a display ( just 99.99% cpu usage) this has the link back to executable.
If I replace the Link in the Bundle with the execuatble, I get the same problem.

If I create the same app for carbon, the application works from Finder and also from bundle whether linked or not.

Any ideas what I am doing wrong ?


The best way to get accurate information on the forum is to post something wrong and wait for corrections.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Cocoa Application not working from bundle.
« Reply #1 on: September 12, 2018, 09:43:52 pm »
Why don’t you share the project?

This page should help you with that.
« Last Edit: September 12, 2018, 10:55:20 pm by skalogryz »

Josh

  • Hero Member
  • *****
  • Posts: 1271
Re: Cocoa Application not working from bundle.
« Reply #2 on: September 14, 2018, 12:34:40 am »
Hi

I am in the proces of minimizing; which includes removing own components and non-sharable code, whilst keeping the probem intake. Taking some time as its quite a large project.

Some other observations, I can run the application thats in the bundle macos folder, either as the shortcut or as the executeable; but not the bundle itself. Which kind of points to a problem with the bundle.

Additional Observation, its as though the application is not showing the main form when run within bundle, as when I monitor Application with activity Monitor, the application is increasing and decreasing the CPU as the application normally does during a normal run, just no display..
« Last Edit: September 14, 2018, 02:05:47 am by josh »
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

Josh

  • Hero Member
  • *****
  • Posts: 1271
Re: Cocoa Application not working from bundle.
« Reply #3 on: September 17, 2018, 05:30:06 pm »
Hi

Done some further test, i created a multiform project, and then put a showmessage in formactivate event; the app runs ok when executable is run, but if you create a bundle and try the bundle then it crashes.
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Cocoa Application not working from bundle.
« Reply #4 on: September 17, 2018, 07:39:21 pm »
but if you create a bundle and try the bundle then it crashes.
do you have a backtrace of the crash? (macOS would offer one by itself)

As well as crash <> 100% CPU use. So we might be facing two different problems.

Josh

  • Hero Member
  • *****
  • Posts: 1271
Re: Cocoa Application not working from bundle.
« Reply #5 on: September 17, 2018, 10:37:58 pm »
Hi

Attached MAC Error Dump Log
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Cocoa Application not working from bundle.
« Reply #6 on: September 17, 2018, 10:56:05 pm »
Try to get the latest trunk and see if it fixes the issue. (there were some changes related to focus notification. The log indicates "becomeFirstResponder" in the stack. So there's a slight chance of the issue to be fixed by now).

seems to be a common problem. Cocoa doesn't like a modality to be invoked either during paint or during activation of another window.

Does it work in Carbon?
« Last Edit: September 17, 2018, 11:03:27 pm by skalogryz »

Josh

  • Hero Member
  • *****
  • Posts: 1271
Re: Cocoa Application not working from bundle.
« Reply #7 on: September 17, 2018, 11:57:51 pm »
Hi

Just updated to laz 2.1.0 svn 59053, fpc 3.3.1

deleted bundle, rebuilt app- recreated bundle, same problem.
works fine in carbon.

The best way to get accurate information on the forum is to post something wrong and wait for corrections.

Josh

  • Hero Member
  • *****
  • Posts: 1271
Re: Cocoa Application not working from bundle.
« Reply #8 on: September 18, 2018, 12:47:32 am »
Hi

The problem is when you place anything that creates a modal in the form onactivate event on Cocoa; but only when its run in the bundle. The executable works on its own.

I will try a work around along the lines of
Code: Pascal  [Select][+][-]
  1. factivated:boolean=false;
  2. form.oncreate;
  3. {$ifdef darwin} // disable form_activate event
  4. form.activate:=nil;
  5. {$endif}
  6.  
  7. form.OnShow;
  8. {$ifdef darwin}  // cannot call modal stuff from on activate but can from form show;
  9. form.show; //force form to display
  10. form.setfocus; // force form focus
  11. if factivated=false then
  12. begin
  13.   factivated:=true;
  14.   form.OnActivate;
  15. end;
  16. {$endif}
  17. .... rest of code for form.show
  18.  

I will test now with my orginal project to see if this idea works.

Unless there is another event I can use in place of the OnActivate event that is called after the form is created and active; but before the form OnShow Event is fired.


« Last Edit: September 18, 2018, 12:49:29 am by josh »
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Cocoa Application not working from bundle.
« Reply #9 on: September 18, 2018, 01:00:04 am »
it works fine in 10.6 hmm

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Cocoa Application not working from bundle.
« Reply #10 on: September 18, 2018, 01:43:36 am »
try this sample!
remember to launch it from bundle. (if the one in archive won't work, simply recreate the bundle)
« Last Edit: September 18, 2018, 01:50:11 am by skalogryz »

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Cocoa Application not working from bundle.
« Reply #11 on: September 18, 2018, 04:26:40 am »
after altermanual test, please update to the latest trunk and try again.

Josh

  • Hero Member
  • *****
  • Posts: 1271
Re: Cocoa Application not working from bundle.
« Reply #12 on: September 18, 2018, 12:09:25 pm »
Just updated laz to 59063

It indeed solves the problem, so I can use showmessages etc in the activate form event :)
I will test with other projects that use this event.

Not sure if its this change that has bought on an issue with IDE Press CMD F or Search FInd, the dialog is not on top and is beneath other windows so is not in view, if you then press CMD F again, you then get an error and Laz will generaly crash.

Edit: Run/Clean Up and Build is also not shown on top; but calling it the second time does not create a crash you just have to find where it is.
Edit: And others too

nb I could not test your attachment as it did not contain and .pas file, just lpi,lpr and the bundle
« Last Edit: September 18, 2018, 12:33:36 pm by josh »
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Cocoa Application not working from bundle.
« Reply #13 on: September 18, 2018, 02:25:20 pm »
nb I could not test your attachment as it did not contain and .pas file, just lpi,lpr and the bundle
.lpr is lazarus project and .lpi is pretty much .pas file.

Not sure if its this change that has bought on an issue with IDE Press CMD F or Search FInd, the dialog is not on top and is beneath other windows so is not in view, if you then press CMD F again, you then get an error and Laz will generaly crash.
it might be. Try to revert the change in CocoaInt.pas file and see if it restores the proper functionality.

Josh

  • Hero Member
  • *****
  • Posts: 1271
Re: Cocoa Application not working from bundle.
« Reply #14 on: September 18, 2018, 02:46:06 pm »
Hi

svn 59063 is causing many problems and strange random crashes, so I will have to go back to 59053.

Yes you application does finally open, after numerous attempts and crashes ( laz crashing). svn 59063
When I re-create the bundle, It crahses and OS error dumo has this. I can run the executable direct.

Quote
Application Specific Information:
*** Terminating app due to uncaught exception 'NSGenericException', reason: '-[NSAlert runModal] may not be invoked inside of transaction begin/commit pair, or inside of transaction commit (usually this means it was invoked inside of a view's -drawRect: method.)'
abort() called
terminating with uncaught exception of type NSException
« Last Edit: September 18, 2018, 02:48:30 pm by josh »
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

 

TinyPortal © 2005-2018