Mac: quitting the application from the dock bypasses OnExit if SetExitOnFrameDelete is false
|Reported by:||joostn||Owned by:||csomor|
|Component:||wxOSX (any toolkit)||Version:||3.0.0|
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?