summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorLeo Lam <leolino.lam@gmail.com>2017-06-03 21:33:43 +0200
committerGitHub <noreply@github.com>2017-06-03 21:33:43 +0200
commit227bc3816f589f4df1d41910d7162f75bca63e45 (patch)
tree01ba4ff7ff1aabea1e661a96bdc35bccf9081322 /Source/Core
parentbcc85f9f4dd3e59a8e27f01ec8a3d2514d53ae94 (diff)
parent546181c4571ddf995fa5cad13596a254f1330491 (diff)
Merge pull request #5517 from leoetlino/more-reliable-shutdown
More reliable shutdown
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Core/Core.cpp69
-rw-r--r--Source/Core/DolphinWX/FrameTools.cpp2
2 files changed, 37 insertions, 34 deletions
diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp
index 60db83c98f..122289c5b0 100644
--- a/Source/Core/Core/Core.cpp
+++ b/Source/Core/Core/Core.cpp
@@ -24,6 +24,7 @@
#include "Common/Logging/LogManager.h"
#include "Common/MemoryUtil.h"
#include "Common/MsgHandler.h"
+#include "Common/ScopeGuard.h"
#include "Common/StringUtil.h"
#include "Common/Thread.h"
#include "Common/Timer.h"
@@ -453,6 +454,19 @@ static void EmuThread()
{
const SConfig& core_parameter = SConfig::GetInstance();
s_is_booting.Set();
+ Common::ScopeGuard flag_guard{[] {
+ s_is_booting.Clear();
+ s_is_started = false;
+ s_is_stopping = false;
+
+ if (s_on_stopped_callback)
+ s_on_stopped_callback();
+
+ INFO_LOG(CONSOLE, "Stop\t\t---- Shutdown complete ----");
+ }};
+
+ // Prevent the UI from getting stuck whenever an error occurs.
+ Common::ScopeGuard stop_message_guard{[] { Host_Message(WM_USER_STOP); }};
Common::SetCurrentThreadName("Emuthread - Starting");
@@ -466,16 +480,23 @@ static void EmuThread()
DeclareAsCPUThread();
Movie::Init();
+ Common::ScopeGuard movie_guard{Movie::Shutdown};
HW::Init();
+ Common::ScopeGuard hw_guard{[] {
+ // We must set up this flag before executing HW::Shutdown()
+ s_hardware_initialized = false;
+ INFO_LOG(CONSOLE, "%s", StopMessage(false, "Shutting down HW").c_str());
+ HW::Shutdown();
+ INFO_LOG(CONSOLE, "%s", StopMessage(false, "HW shutdown").c_str());
+ }};
if (!g_video_backend->Initialize(s_window_handle))
{
- s_is_booting.Clear();
PanicAlert("Failed to initialize video backend!");
- Host_Message(WM_USER_STOP);
return;
}
+ Common::ScopeGuard video_guard{[] { g_video_backend->Shutdown(); }};
OSD::AddMessage("Dolphin " + g_video_backend->GetName() + " Video Backend.", 5000);
@@ -486,11 +507,7 @@ static void EmuThread()
if (!DSP::GetDSPEmulator()->Initialize(core_parameter.bWii, core_parameter.bDSPThread))
{
- s_is_booting.Clear();
- HW::Shutdown();
- g_video_backend->Shutdown();
PanicAlert("Failed to initialize DSP emulation!");
- Host_Message(WM_USER_STOP);
return;
}
@@ -520,7 +537,18 @@ static void EmuThread()
Wiimote::LoadConfig();
}
+ Common::ScopeGuard controller_guard{[init_controllers] {
+ if (!init_controllers)
+ return;
+
+ Wiimote::Shutdown();
+ Keyboard::Shutdown();
+ Pad::Shutdown();
+ g_controller_interface.Shutdown();
+ }};
+
AudioCommon::InitSoundStream();
+ Common::ScopeGuard audio_guard{AudioCommon::ShutdownSoundStream};
// The hardware is initialized.
s_hardware_initialized = true;
@@ -617,40 +645,15 @@ static void EmuThread()
if (core_parameter.bCPUThread)
g_video_backend->Video_Cleanup();
- // We must set up this flag before executing HW::Shutdown()
- s_hardware_initialized = false;
- INFO_LOG(CONSOLE, "%s", StopMessage(false, "Shutting down HW").c_str());
- HW::Shutdown();
- INFO_LOG(CONSOLE, "%s", StopMessage(false, "HW shutdown").c_str());
-
- if (init_controllers)
- {
- Wiimote::Shutdown();
- Keyboard::Shutdown();
- Pad::Shutdown();
- g_controller_interface.Shutdown();
- init_controllers = false;
- }
-
- g_video_backend->Shutdown();
- AudioCommon::ShutdownSoundStream();
-
- INFO_LOG(CONSOLE, "%s", StopMessage(true, "Main Emu thread stopped").c_str());
-
// Clear on screen messages that haven't expired
OSD::ClearMessages();
BootManager::RestoreConfig();
- INFO_LOG(CONSOLE, "Stop [Video Thread]\t\t---- Shutdown complete ----");
- Movie::Shutdown();
PatchEngine::Shutdown();
HLE::Clear();
-
- s_is_stopping = false;
-
- if (s_on_stopped_callback)
- s_on_stopped_callback();
+ // If we shut down normally, the stop message does not need to be triggered.
+ stop_message_guard.Dismiss();
}
// Set or get the running state
diff --git a/Source/Core/DolphinWX/FrameTools.cpp b/Source/Core/DolphinWX/FrameTools.cpp
index 7f538563b5..b59720ad71 100644
--- a/Source/Core/DolphinWX/FrameTools.cpp
+++ b/Source/Core/DolphinWX/FrameTools.cpp
@@ -810,7 +810,6 @@ void CFrame::DoStop()
// don't let this function run again until it finishes, or is aborted.
m_confirm_stop = true;
- m_is_game_loading = false;
if (Core::GetState() != Core::State::Uninitialized || m_render_parent != nullptr)
{
#if defined __WXGTK__
@@ -911,6 +910,7 @@ bool CFrame::TriggerSTMPowerEvent()
void CFrame::OnStopped()
{
m_confirm_stop = false;
+ m_is_game_loading = false;
m_tried_graceful_shutdown = false;
UninhibitScreensaver();