Why is HumanClientApp::ExitApp() called twice?

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Post Reply
Message
Author
User avatar
swaq
Space Dragon
Posts: 384
Joined: Tue Aug 20, 2019 1:56 pm

Why is HumanClientApp::ExitApp() called twice?

#1 Post by swaq »

Code: Select all

19:54:40.799401 {0x00007faa5e7b0780} [debug] client : HumanClientApp.cpp:734 : Save games completed.
19:54:40.913974 {0x00007faa5e7b0780} [info] client : i18n.cpp:120 : Global locale: en_US.UTF-8
19:54:44.851116 {0x00007faa5e7b0780} [debug] client : HumanClientApp.cpp:1139 : HumanClientApp::HandleAppQuitting()
19:54:44.851177 {0x00007faa5e7b0780} [debug] client : HumanClientApp.cpp:1439 : HumanClientApp::ExitApp
19:54:44.851512 {0x00007faa5e7b0780} [debug] client : HumanClientApp.cpp:1387 : Turn 0 autosave to: /home/wood/.local/share/freeorion/save/auto/FreeOrion_Human_Player_Terran_0001_20191013_195444.sav
19:54:44.851543 {0x00007faa5e7b0780} [debug] client : HumanClientApp.cpp:1389 : Autosave to: /home/wood/.local/share/freeorion/save/auto/FreeOrion_Human_Player_Terran_0001_20191013_195444.sav
19:54:44.851558 {0x00007faa5e7b0780} [debug] client : HumanClientApp.cpp:1391 : End of play autosave to: /home/wood/.local/share/freeorion/save/auto/FreeOrion_Human_Player_Terran_0001_20191013_195444.sav
19:54:44.851583 {0x00007faa5e7b0780} [debug] client : HumanClientApp.cpp:724 : Sent save initiate message to server.
19:54:44.851596 {0x00007faa5e7b0780} [debug] client : HumanClientApp.cpp:1473 : save game in progress. Checking with player.
19:54:44.859468 {0x00007faa5e7b0780} [debug] client : HumanClientApp.cpp:1139 : HumanClientApp::HandleAppQuitting()
19:54:44.859571 {0x00007faa5e7b0780} [debug] client : HumanClientApp.cpp:1439 : HumanClientApp::ExitApp
19:54:44.859581 {0x00007faa5e7b0780} [debug] client : HumanClientApp.cpp:1473 : save game in progress. Checking with player.
19:54:44.930825 {0x00007faa5e7b0780} [debug] client : HumanClientApp.cpp:734 : Save games completed.
19:54:44.930868 {0x00007faa5e7b0780} [debug] client : HumanClientApp.cpp:1487 : SaveGamePendingDialog::SaveCompletedHandler save game completed handled.
19:54:44.930882 {0x00007faa5e7b0780} [debug] client : HumanClientApp.cpp:1487 : SaveGamePendingDialog::SaveCompletedHandler save game completed handled.
19:54:44.949658 {0x00007faa5e7b0780} [debug] FSM : HumanClientFSM.cpp:1151 : Sending server shutdown message.
19:54:44.973093 {0x00007faa2cff9700} [debug] network : ClientNetworking.cpp:506 : Client connection disconnected by EOF from server.
19:54:44.982716 {0x00007faa5e7b0780} [debug] FSM : HumanClientFSM.cpp:1205 : QuittingGame terminated server process.
19:54:44.982810 {0x00007faa5e7b0780} [debug] client : Process.cpp:271 : Process::Impl::Kill calling kill(m_process_id, SIGKILL)
19:54:44.982840 {0x00007faa5e7b0780} [debug] client : Process.cpp:273 : Process::Impl::Kill calling waitpid(m_process_id, &status, 0)
19:54:44.990806 {0x00007faa5e7b0780} [debug] client : Process.cpp:275 : Process::Impl::Kill done
19:54:44.990942 {0x00007faa5e7b0780} [debug] client : chmain.cpp:322 : Human client main exited cleanly.
19:54:44.990958 {0x00007faa5e7b0780} [debug] client : HumanClientApp.cpp:387 : HumanClientApp exited cleanly.
Does anyone know why ExitApp() is run twice? I am working on a solution to Issue #2551 and the dialog box pops up twice when I try to close the application.

User avatar
alleryn
Space Dragon
Posts: 259
Joined: Sun Nov 19, 2017 6:32 pm

Re: Why is HumanClientApp::ExitApp() called twice?

#2 Post by alleryn »

Disclaimer: I'm out of my depth here, so what i have to say may not be very helpful.

Looks to me like HandleAppQuitting is bound to WindowClosingSignal (fired by SDL_WINDOWEVENT_CLOSE) and also to AppQuittingSignal (fired by SDL_QUIT). [SDL = Simple DirectMedia Layer]

SDL is cross-platform, so when these SDL events fire is going to be platform dependent, and also depends on how you close the application. I did a couple of tests on singleplayer games on my Windows 10 Home System (v0.4.8+ [build 2019-10-12.f8cbdef]):
  • Started singleplayer game, exited by clicking the X in the upperrighthandcorner of window. This gave similar results to what you saw. Two instances of HandleAppQuitting() which led to two instances of ExitApp(). My guess here [Recall Out of Depth Disclaimer] is that there's one SDL_WINDOWEVENT_CLOSE and one SDL_QUIT.
  • Started singleplayer game, exited via resign button. This gave one ExitApp() and zero HandleAppQuitting(). It looks like it got to ExitApp() via [debug] client : HumanClientApp.cpp:1527 : HumanClientApp::DisconnectedFromServer. I guess it has something to do with this line: m_fsm->process_event(Disconnection()), but i stopped digging there.
Hope this helps.

Edit: As far as practical implementation, i'm not sure what good coding practice is, but my kludge would be to put some kind of timer on the dialog box so that it will only open if it hasn't opened in the last, you know, 2 seconds or something. But there's probably a more sophisticated way to do it.

User avatar
Vezzra
Release Manager, Design
Posts: 6090
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

Re: Why is HumanClientApp::ExitApp() called twice?

#3 Post by Vezzra »

alleryn wrote: Mon Oct 14, 2019 3:12 amAs far as practical implementation, i'm not sure what good coding practice is, but my kludge would be to put some kind of timer on the dialog box so that it will only open if it hasn't opened in the last, you know, 2 seconds or something. But there's probably a more sophisticated way to do it.
Don't know about sophisticated, but what I'd do if I want to prevent a code section which potentially could be called multiple times from different points to be executed more that once is using a simple flag.

Introduce a flag "exit_app_handled", check it inside ExitApp() before doing anything. If it is already set, return immediately, otherwise set it and execute the cleanup code.

Or am I missing something obvious...?

User avatar
swaq
Space Dragon
Posts: 384
Joined: Tue Aug 20, 2019 1:56 pm

Re: Why is HumanClientApp::ExitApp() called twice?

#4 Post by swaq »

There is actually already a flag (was_playing) being set to keep from autosaving there more than once so I was planning on using that if the ExitApp() function being called more than once was expected behavior. I just need to be careful about setting things back if the close is aborted.

Post Reply