Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wxtrac opened this issue Apr 22, 2014 · 7 comments
Labels

Comments

@wxtrac
Copy link
Collaborator

wxtrac commented Apr 22, 2014

Issue migrated from trac ticket # 16200

component: wxOSX (any toolkit) | priority: normal | resolution: fixed | keywords: OnExit SetExitOnFrameDelete

2014-04-22 15:01:06: joostn (Joost Nieuwenhuijse) created the issue


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?

@wxtrac
Copy link
Collaborator Author

wxtrac commented Apr 22, 2014

2014-04-22 15:01:56: joostn (Joost Nieuwenhuijse) uploaded file minimal.cpp (1.7 KiB)

Minimal sample showing the bug

@wxtrac
Copy link
Collaborator Author

wxtrac commented Apr 22, 2014

2014-04-22 15:02:16: joostn (Joost Nieuwenhuijse) uploaded file 0001-patch-mac-Quit-from-dock-doesn-t-call-OnExit-if-Exit.patch (1.1 KiB)

patch

@wxtrac
Copy link
Collaborator Author

wxtrac commented Apr 22, 2014

2014-04-22 16:14:07: joostn (Joost Nieuwenhuijse) commented


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?

@wxtrac
Copy link
Collaborator Author

wxtrac commented Apr 22, 2014

2014-04-22 21:40:47: @csomor changed status from new to accepted

@wxtrac
Copy link
Collaborator Author

wxtrac commented Apr 22, 2014

2014-04-22 23:21:21: @csomor changed status from accepted to closed

2014-04-22 23:21:21: @csomor changed resolution from ** to fixed

2014-04-22 23:21:21: @csomor commented

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

@wxtrac wxtrac closed this as completed Apr 22, 2014
@wxtrac
Copy link
Collaborator Author

wxtrac commented Apr 25, 2014

2014-04-25 09:38:02: dgud commented


Can this fix be added WX_3_0_BRANCH also, please?

@wxtrac
Copy link
Collaborator Author

wxtrac commented Apr 25, 2014

2014-04-25 15:02:51: @csomor commented


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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant