OSX: use SafelyProcessEvent from Handlers

22 views
Skip to first unread message

Stefan Csomor

unread,
Feb 3, 2026, 4:47:36 PM (2 days ago) Feb 3
to wx-...@googlegroups.com
Hi

as I was going through the exception code I saw several places where I think I should use SafelyProcessEvent instead of the ProcessEvent, mainly in callbacks that are coming from the native OS, 

eg the wxNSAppController applicationWillTerminate does call OSXOnWillTerminate which calls ProcessEvent but I think it should be made exception safe

Am I overlooking something ? Thoughts and ideas ?

Thanks,

Stefan

Vadim Zeitlin

unread,
Feb 4, 2026, 8:58:09 AM (yesterday) Feb 4
to wx-...@googlegroups.com
On Tue, 3 Feb 2026 21:47:27 +0000 'Stefan Csomor' via wx-dev wrote:

SC> as I was going through the exception code I saw several places where I think I should use SafelyProcessEvent instead of the ProcessEvent, mainly in callbacks that are coming from the native OS,

Hello,

I am not sure if C++ exceptions can safely propagate through the OS code in macOS, but I think this might be the case. And, if so, we only need to use SafelyProcessEvent() only in the code which doesn't contain our own stack frames further up the stack.

SC> eg the wxNSAppController applicationWillTerminate does call OSXOnWillTerminate which calls ProcessEvent but I think it should be made exception safe

Where is handleQuitAppEvent:withReplyEvent: itself is being called for? If it's called from inside wxGUIEventLoop::OSXDoRun(), then using SafelyProcessEvent() in it is probably not needed. OTOH adding it probably shouldn't do any harm either, especially if the stored exception is processed in the end somewhere.

Thanks for looking at this!
VZ

Stefan Csomor

unread,
Feb 4, 2026, 9:57:22 AM (yesterday) Feb 4
to wx-...@googlegroups.com
this is the stack trace for the OSXOnWillTerminate situation, it is in frame 0, while OSXDoRun is in frame 21, I’m hesitant whether skipping all these native Cocoa/OS frames is a good idea ...

#0     in wxApp::OSXOnWillTerminate at ..
#1     in -[wxNSAppController applicationWillTerminate:] at ..
#2     in __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ ()
#3     in ___CFXRegistrationPost_block_invoke ()
#4     in _CFXRegistrationPost ()
#5     in _CFXNotificationPost ()
#6     in -[NSNotificationCenter postNotificationName:object:userInfo:] ()
#7     in -[NSApplication terminate:] ()
#8     in -[NSApplication _terminateFromSender:askIfShouldTerminate:saveWindows:] ()
#9     in __52-[NSApplication(NSAppleEventHandling) _handleAEQuit]_block_invoke ()
#10    in ___NSMainRunLoopPerformBlockInModes_block_invoke ()
#11    in __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ ()
#12    in __CFRunLoopDoBlocks ()
#13    in __CFRunLoopRun ()
#14    in CFRunLoopRunSpecific ()
#15    in RunCurrentEventLoopInMode ()
#16    in ReceiveNextEventCommon ()
#17    in _BlockUntilNextEventMatchingListInModeWithFilter ()
#18    in _DPSNextEvent ()
#19    in -[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] ()
#20    in -[NSApplication run] ()
#21    in wxGUIEventLoop::OSXDoRun at ...

Am 04.02.26, 14:58 schrieb "wx-...@googlegroups.com" <wx-...@googlegroups.com>:
Reply all
Reply to author
Forward
0 new messages