Recent

Author Topic: [TCocoaMenuItem _setMenuOwner:]: unrecognized selector sent to instance  (Read 6506 times)

Renat.Su

  • Full Member
  • ***
  • Posts: 230
    • Renat.Su
Can anyone hint me? I tried to run the cross-compiled app in MacOS x. x86_64 / widget - Cocoa. Do I understand correctly that the problem seems to be because of TrayIcon or Main menu? Everything is fine on other platforms
Code: [Select]
2018-04-16 16:08:24.378 foxwhois[4505:271601] -[TCocoaMenuItem _setMenuOwner:]: unrecognized selector sent to instance 0x100d8b640

2018-04-16 16:08:24.390 foxwhois[4505:271601] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TCocoaMenuItem _setMenuOwner:]: unrecognized selector sent to instance 0x100d8b640'

*** First throw call stack:

(

0   CoreFoundation                      0x00007fff3a21bfcb __exceptionPreprocess + 171

1   libobjc.A.dylib                     0x00007fff60eb9c76 objc_exception_throw + 48

2   CoreFoundation                      0x00007fff3a2b4a24 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132

3   CoreFoundation                      0x00007fff3a192610 ___forwarding___ + 1456

4   CoreFoundation                      0x00007fff3a191fd8 _CF_forwarding_prep_0 + 120

5   AppKit                              0x00007fff37eff98c -[NSStatusItem setMenu:] + 101

6   foxwhois                            0x00000001001f56ad -[TCocoaStatusItemHandle lclSetTrayIcon:] + 237

7   foxwhois                            0x00000001001f5882 COCOAWSEXTCTRLS$_$TCOCOAWSCUSTOMTRAYICON_$__$$_INTERNALUPDATE$TCUSTOMTRAYICON + 66

8   foxwhois                            0x000000010018c609 EXTCTRLS$_$TCUSTOMTRAYICON_$__$$_ICONCHANGED$TOBJECT + 57

9   foxwhois                            0x00000001000d6bcf GRAPHICS$_$TGRAPHIC_$__$$_CHANGED$TOBJECT + 55

10  foxwhois                            0x00000001000daeef GRAPHICS$_$TRASTERIMAGE_$__$$_CHANGED$TOBJECT + 63

11  foxwhois                            0x00000001000daa82 GRAPHICS$_$TRASTERIMAGE_$__$$_ENDUPDATE$BOOLEAN + 194

12  foxwhois                            0x00000001000e7bcf GRAPHICS$_$TCUSTOMICON_$__$$_ASSIGN$TPERSISTENT + 375

13  foxwhois                            0x000000010018c885 EXTCTRLS$_$TCUSTOMTRAYICON_$__$$_SETICON$TICON + 69

14  foxwhois                            0x000000010003598d MNFRM$_$TFRMMAIN_$__$$_FORMSHOW$TOBJECT + 685

15  foxwhois                            0x000000010001bff4 FORMS$_$TCUSTOMFORM_$__$$_CMSHOWINGCHANGED$TLMESSAGE + 84

16  foxwhois                            0x000000010000c753 SYSTEM$_$TOBJECT_$__$$_DISPATCH$formal + 203

17  foxwhois                            0x0000000100166a8e CONTROLS$_$TWINCONTROL_$__$$_WNDPROC$TLMESSAGE + 806

18  foxwhois                            0x000000010001df1e FORMS$_$TCUSTOMFORM_$__$$_WNDPROC$TLMESSAGE + 622

19  foxwhois                            0x0000000100171126 CONTROLS$_$TCONTROL_$__$$_PERFORM$LONGWORD$WPARAM$LPARAM$$LRESULT + 86

20  foxwhois                            0x0000000100164998 CONTROLS$_$TWINCONTROL_$_UPDATESHOWING_$$_CHANGESHOWING$BOOLEAN + 184

21  foxwhois                            0x00000001001648d3 CONTROLS$_$TWINCONTROL_$__$$_UPDATESHOWING + 307

22  foxwhois                            0x0000000100021036 FORMS$_$TCUSTOMFORM_$__$$_UPDATESHOWING + 142

23  foxwhois                            0x0000000100162ee7 CONTROLS$_$TWINCONTROL_$__$$_DOALLAUTOSIZE + 647

24  foxwhois                            0x000000010017a881 CONTROLS$_$TCONTROL_$__$$_ENABLEAUTOSIZING + 313

25  foxwhois                            0x0000000100177fca CONTROLS$_$TCONTROL_$__$$_SETVISIBLE$BOOLEAN + 418

26  foxwhois                            0x000000010001baa1 FORMS$_$TCUSTOMFORM_$__$$_SETVISIBLE$BOOLEAN + 113

27  foxwhois                            0x0000000100020580 FORMS$_$TCUSTOMFORM_$__$$_SHOW + 232

28  foxwhois                            0x0000000100028568 FORMS$_$TAPPLICATION_$__$$_RUN + 56

29  foxwhois                            0x00000001000011f1 PASCALMAIN + 401

)

libc++abi.dylib: terminating with uncaught exception of type NSException

Abort trap: 6

logout

Saving session...

...copying shared history...

...saving history...truncating history files...

...completed.
« Last Edit: April 16, 2018, 05:37:58 pm by Renat.Su »

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
apparently the private API _setMenuOwner was removed from macOS.

What's your version?

Renat.Su

  • Full Member
  • ***
  • Posts: 230
    • Renat.Su
Lazarus 1.8.2 r57578M FPC 3.0.4 x86_64-linux-gtk2

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Sorry, what macOS version?

Renat.Su

  • Full Member
  • ***
  • Posts: 230
    • Renat.Su
User said that
Quote
MacOS High Sierra 10.13.3
64 бит
« Last Edit: April 16, 2018, 08:28:15 pm by Renat.Su »

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
ok, so the problem is with Handles used (within LCL internally).
LCLCocoa is acting pretty carelessly in this case, yet I'd anticipate that the issue might be with the code itself.

The question: how do you assign PopupMenu property for TTrayIcon control?

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Renat.Su, just a heads up.

 I found TrayIcon leaked memory on both Carbon and Cocoa when I tried to use it some months ago. Might be a bit hard to detect if you are running a cross compiled binary so be careful.

David
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Renat.Su

  • Full Member
  • ***
  • Posts: 230
    • Renat.Su
ok, so the problem is with Handles used (within LCL internally).
LCLCocoa is acting pretty carelessly in this case, yet I'd anticipate that the issue might be with the code itself.

The question: how do you assign PopupMenu property for TTrayIcon control?
So, standard method for assigning... But I found But I found one questionable code part in FormShow event
Code: [Select]
  if FOnCreate then
  begin
.......
    TryIcn.Icon:=Application.Icon; // Can be in this line mistake?
.......
    FOnCreate:=False;
  end;
I will try to compile with the commented line

Renat.Su

  • Full Member
  • ***
  • Posts: 230
    • Renat.Su
Renat.Su, just a heads up.

 I found TrayIcon leaked memory on both Carbon and Cocoa when I tried to use it some months ago. Might be a bit hard to detect if you are running a cross compiled binary so be careful.

David
Thank you for valuable nuance!

Renat.Su

  • Full Member
  • ***
  • Posts: 230
    • Renat.Su
So, the problem was in that line in the implementation of the OnShow event of the main form.
Code: Pascal  [Select][+][-]
  1.  //   TryIcn.Icon:=Application.Icon;
  2. // Caused an error in Mac OS
Thank you all for advice!

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: [TCocoaMenuItem _setMenuOwner:]: unrecognized selector sent to instance
« Reply #10 on: April 21, 2018, 03:52:35 pm »
The line shouldn't cause an error on macOS.

Could you please update cocoa widgetset to the latest revision and try again?

Renat.Su

  • Full Member
  • ***
  • Posts: 230
    • Renat.Su
Re: [TCocoaMenuItem _setMenuOwner:]: unrecognized selector sent to instance
« Reply #11 on: April 21, 2018, 04:27:25 pm »
The line shouldn't cause an error on macOS.

Could you please update cocoa widgetset to the latest revision and try again?
I'm using the latest stable version Lazarus/FPC. Do you mean to download and install the trunk Lazarus/FPC?

I will add that the icon did not exist. It was supposed to come from the source folder, but it wasn't there. However in Linux it did not cause the failure.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: [TCocoaMenuItem _setMenuOwner:]: unrecognized selector sent to instance
« Reply #12 on: April 21, 2018, 04:43:48 pm »
I'm using the latest stable version Lazarus/FPC. Do you mean to download and install the trunk Lazarus/FPC?
Unfortunately, the term "stable" might not apply to Cocoa widgetset. Using trunk version for Cocoa is preferred

I will add that the icon did not exist. It was supposed to come from the source folder, but it wasn't there. However in Linux it did not cause the failure.
on Cocoa (and macOS) in general, the executable is not located in the source code. Instead it's located within a bundle (a special directory structure).
The image should be placed within the same bundle into a resource directory.
Thus the code that loads an image
Code: [Select]
  Icon.LoadFromFile('icon.png')
would not work for OSX (unless you change current directory to the resource directory of the bundle) .

Yet again,
Code: [Select]
TrayIcon.Icon := Application.Icon;
should work just fine. (and it does work fine for Cocoa trunk)

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: [TCocoaMenuItem _setMenuOwner:]: unrecognized selector sent to instance
« Reply #13 on: April 22, 2018, 02:07:37 am »
Renat.Su, I can confirm what skalogryz says, cocoa in the Trunk is heaps better than in 1.8 release. (And quite a bit of the improvement is due to skalogryz I suspect).

This thread has a simple recipe for downloading and starting up a trunk version on a system that already has a working 1.8 and it won't, in any way, interfere with your 1.8 install.
https://forum.lazarus.freepascal.org/index.php/topic,40883.30.html

If you read the whole thread, you will see it has become about an IDE problem in Trunk at present so you will need to build your app and then run it outside the IDE. Don't forget to make an application bundle.

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Renat.Su

  • Full Member
  • ***
  • Posts: 230
    • Renat.Su
Re: [TCocoaMenuItem _setMenuOwner:]: unrecognized selector sent to instance
« Reply #14 on: April 24, 2018, 09:03:15 am »
Thanks! I'll try to check it out. Now it seems to have earned the tester when I removed the specified line. The problem is simply that I do not have MacOS, but there is a tester that sometimes checks the ability of the MacOS build

 

TinyPortal © 2005-2018