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
wx hangs when quit from Dock on macOS #5603
Comments
This is tricky, see these code snippets:
It appears that as long as the Erlang VM that started wx runs, the "app" keeps running: it is in the Dock, can be switched to with cmd+tab, etc. |
I think the linked code snippets might be handling quitting from the Apple Menu only including keyboard shortcuts Quitting from the Dock seems like another beast. When it happens I was able to trace a wx_object process while such quitting happened and two things happened. The process received Line 458 in eef2e70
If |
Right. So eg observer correctly handles |
Yes quitting from the Apple Menu is handled as |
My private mac have died so I have problems debugging on mac, so I need some help with this. Mac doesn't really like mixing console command and gui and erlang tries exactly that, so it requires some hacks, But if you can help out with improvements in this area it would be great. |
@dgud @leoliu I did some digging and found how wx handles the "quit" app event: (
The Here's one possible implementation, one where we send a commit 86284130513818aa6923ee0fbbef621afddc298f
Author: Wojtek Mach <wojtek@wojtekmach.pl>
Date: Sat Apr 16 23:21:29 2022 +0200
wip
diff --git a/lib/wx/c_src/wxe_impl.cpp b/lib/wx/c_src/wxe_impl.cpp
index 67b319b036..f49d3e91c5 100644
--- a/lib/wx/c_src/wxe_impl.cpp
+++ b/lib/wx/c_src/wxe_impl.cpp
@@ -224,6 +224,11 @@ void WxeApp::MacReopenApp() {
wxString empty;
send_msg("reopen_app", &empty);
}
+
+void WxeApp::OSXOnWillTerminate() {
+ wxString empty;
+ send_msg("quit_app", &empty);
+}
#endif
void WxeApp::shutdown(wxeMetaCommand& Ecmd) {
@@ -233,7 +238,8 @@ void WxeApp::shutdown(wxeMetaCommand& Ecmd) {
}
void WxeApp::dummy_close(wxEvent& Ev) {
- // fprintf(stderr, "Dummy Close invoked\r\n");
+ wxString empty;
+ send_msg("quit_app", &empty);
// wxMac really wants a top level window which command-q quits if there are no
// windows open, and this will kill the erlang, override default handling
}
diff --git a/lib/wx/c_src/wxe_impl.h b/lib/wx/c_src/wxe_impl.h
index 16487f3c0d..9210683f16 100644
--- a/lib/wx/c_src/wxe_impl.h
+++ b/lib/wx/c_src/wxe_impl.h
@@ -64,6 +64,7 @@ public:
virtual void MacOpenURL(const wxString &url);
virtual void MacNewFile();
virtual void MacReopenApp();
+ virtual void OSXOnWillTerminate();
#endif
void init_consts(wxeMetaCommand& event);
diff --git a/lib/wx/src/wxe_master.erl b/lib/wx/src/wxe_master.erl
index 5724457ae7..c899e9f707 100644
--- a/lib/wx/src/wxe_master.erl
+++ b/lib/wx/src/wxe_master.erl
@@ -178,7 +178,7 @@ handle_info({wxe_driver, debug, Msg}, State) ->
{noreply, State};
handle_info({wxe_driver, Cmd, File}, State = #state{subscribers=Subs, msgs=Msgs})
when Cmd =:= open_file; Cmd =:= new_file; Cmd =:= print_file;
- Cmd =:= open_url; Cmd =:= reopen_app ->
+ Cmd =:= open_url; Cmd =:= reopen_app; Cmd =:= quit_app ->
lists:foreach(fun(Pid) -> Pid ! {Cmd, File} end, Subs),
{noreply, State#state{msgs=[{Cmd, File}|Msgs]}};
handle_info({'DOWN', _Ref, process, Pid, _Info}, State) -> And here's an example shell session:
I even thrown in a default implementation of the "Quit" menu item that sends the same message. While we can do whatever we want in the menu item handler, Apple really wants us to quit the app in the app quit handler (we get a beachball otherwise), thus the only sensible thing to do there is to Please let me know if this seems worth pursuing! |
Thank you so much for looking into this issue. I think I was investigating this issue in Jan however my C++ skill probably made it much harder. But I think this info is relevant (taken from https://docs.wxwidgets.org/latest/classwx_close_event.html):
Also this bug may also happen on other platforms. On windows for example, let's say your wx app is rendering a website using webview with edge backend. Go and uninstall the webview2 SDK. Another issue is before quitting, |
Describe the bug
wx
doesn't handle some Quit events on macOS properly and can hang forever.To Reproduce
wx:new()
, or just start observer like soobserver:start()
Quit
Expected behavior
should process such events and do the right thing.
Affected versions
Erlang/OTP 24.2, wxwidgets 3.1.5 on macOS Big Sur 11.6.2
Additional context
Quitting from the Dock on macOS seems problematic for all apps based on wx (OTP). This might be related to some upstream change as shown in https://forums.wxwidgets.org/viewtopic.php?t=37456
While investigating this issue the beam segment faulted multiple times, a few of them happened when tracing is enabled on a wx_object process. I will report the bug with more details later. Here is an example:
The text was updated successfully, but these errors were encountered: