Page 1 of 1

The sonoma effect ...

Posted: Tue Nov 21, 2023 8:48 pm
by infratec
In my case a program crashes with sonoma, it works on older macOS versions.

After digging arround I found the fault:

I use cocoa messages to set the text in the menubar 'by hand'.
In one case this was done from a thread which handles websocket stuff.

In sonoma seetings of the menubar (SetTitle) is not longer possible from an other thread then the main thread.
I needed a PostEvent() and do this stuff in the main event loop.

Maybe this saves someone else many hours of searching. :wink:

Re: The sonoma effect ...

Posted: Tue Nov 21, 2023 9:51 pm
by mk-soft
It has always been like this.
You have to make the CocoaMessage threadsafe and create your own pool in the thread, because in the event management of PB the pool is cleaned up in the passage of (Wait)WindowEvent and thus your cocoa message is destroyed in the thread.

Code: Select all

;- MacOS make cocoa message threadsafe by mk-soft

Threaded IsThreaded = #True
IsThreaded = #False

Procedure foo(*data)
  Protected Pool
  
  If IsThreaded
    Pool = CocoaMessage(0, 0, "NSAutoreleasePool new")
    Debug "Function is inside thread"
  Else
    Debug "Function is inside main"
  EndIf
  
  ; Do Any
  Debug "Do any"
  
  If Pool
    CocoaMessage(0, Pool, "release")
  EndIf
EndProcedure

foo(0)
Delay(500)

CreateThread(@foo(), 0)
Delay(500)
But is better to use PostEvent ...

Re: The sonoma effect ...

Posted: Wed Nov 29, 2023 4:36 pm
by Piero
mk-soft wrote: Tue Nov 21, 2023 9:51 pm It has always been like this.
You have to make the CocoaMessage threadsafe and create your own pool in the thread, because in the event management of PB the pool is cleaned up in the passage of (Wait)WindowEvent and thus your cocoa message is destroyed in the thread.
Image
Cocoa, threads, clean pools... I told you: you are repetitive!

NOTE: this is to make mk-soft laugh; it is NOT meant to be offensive in ANY way!