The sonoma effect ...

Mac OSX specific forum
infratec
Always Here
Always Here
Posts: 7618
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

The sonoma effect ...

Post 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:
User avatar
mk-soft
Always Here
Always Here
Posts: 6245
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: The sonoma effect ...

Post 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 ...
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Piero
Addict
Addict
Posts: 923
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: The sonoma effect ...

Post 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!
Post Reply