Opened 8 months ago

Closed 8 months ago

Last modified 8 months ago

#16200 closed defect (fixed)

Mac: quitting the application from the dock bypasses OnExit if SetExitOnFrameDelete is false

Reported by: joostn Owned by: csomor
Priority: normal Milestone:
Component: wxOSX (any toolkit) Version: 3.0.0
Keywords: OnExit SetExitOnFrameDelete Cc: joost@…
Blocked By: Blocking:
Patch: yes

Description

See attached minimal sample: if we do Quit from the app's context menu in the dock, OnExit never gets called. Instead exit() is called which proceeds to delete all global objects. This only happens if we set wxApp::SetExitOnFrameDelete(false).

This is what I think what happens: if ExitOnFrameDelete is true, wxApp::OSXOnShouldTerminate closes the main window, which in turns calls wxApp::ExitMainLoop(). Upon exiting the main loop, wxApp::OnExit is called. If ExitOnFrameDelete is false, ExitMainLoop doesn't get called. NSApplication will call OSXOnWillTerminate -> [NSApplication terminate] -> exit(), completely bypassing wxwidgets cleanup.

I've made a patch which seems to fix it but I'm not sure if this is the right solution.

On a side note, if I understand things correctly, it is never OK if wxApp::OSXOnWillTerminate gets called. So we could place a wxASSERT there. And OSXOnShouldTerminate should always return false to ensure that the normal wx cleanup sequence is performed. Right?

Attachments (2)

minimal.cpp download (1.7 KB) - added by joostn 8 months ago.
Minimal sample showing the bug
0001-patch-mac-Quit-from-dock-doesn-t-call-OnExit-if-Exit.patch download (1.1 KB) - added by joostn 8 months ago.
patch

Download all attachments as: .zip

Change History (7)

Changed 8 months ago by joostn

Minimal sample showing the bug

comment:1 Changed 8 months ago by joostn

My patch doesn't work correctly, it results in OnExit being called before all windows have been destroyed.

Stefan, I think you know how to fix this better than I do?

comment:2 Changed 8 months ago by csomor

  • Owner set to csomor
  • Status changed from new to accepted

comment:3 Changed 8 months ago by SC

  • Resolution set to fixed
  • Status changed from accepted to closed

In 76392:

add our own Apple Event handler for the quit app event, fixes #16200

comment:4 Changed 8 months ago by dgud

  • Version changed from dev-latest to 3.0.0

Can this fix be added WX_3_0_BRANCH also, please?

comment:5 Changed 8 months ago by SC

In 76395:

backport, add our own Apple Event handler for the quit app event, see #16200

Note: See TracTickets for help on using tickets.