Skip to content
Permalink
Browse files
Merge pull request #9086 from JosJuice/wiimote-init-order
Core: Run Wiimote::Initialize before HW::Init to avoid crash
  • Loading branch information
JMC47 committed Sep 16, 2020
2 parents e0117a8 + de7ef47 commit e4e5069
Showing 1 changed file with 48 additions and 48 deletions.
@@ -436,54 +436,6 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
DeclareAsCPUThread();
s_frame_step = false;

Movie::Init(*boot);
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());

// Clear on screen messages that haven't expired
OSD::ClearMessages();

// The config must be restored only after the whole HW has shut down,
// not when it is still running.
BootManager::RestoreConfig();

PatchEngine::Shutdown();
HLE::Clear();
}};

VideoBackendBase::PopulateBackendInfo();

if (!g_video_backend->Initialize(wsi))
{
PanicAlert("Failed to initialize video backend!");
return;
}
Common::ScopeGuard video_guard{[] { g_video_backend->Shutdown(); }};

// Render a single frame without anything on it to clear the screen.
// This avoids the game list being displayed while the core is finishing initializing.
g_renderer->BeginUIFrame();
g_renderer->EndUIFrame();

if (cpu_info.HTT)
SConfig::GetInstance().bDSPThread = cpu_info.num_cores > 4;
else
SConfig::GetInstance().bDSPThread = cpu_info.num_cores > 2;

if (!DSP::GetDSPEmulator()->Initialize(core_parameter.bWii, core_parameter.bDSPThread))
{
PanicAlert("Failed to initialize DSP emulation!");
return;
}

// The frontend will likely have initialized the controller interface, as it needs
// it to provide the configuration dialogs. In this case, instead of re-initializing
// entirely, we switch the window used for inputs to the render window. This way, the
@@ -542,6 +494,54 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
g_controller_interface.Shutdown();
}};

Movie::Init(*boot);
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());

// Clear on screen messages that haven't expired
OSD::ClearMessages();

// The config must be restored only after the whole HW has shut down,
// not when it is still running.
BootManager::RestoreConfig();

PatchEngine::Shutdown();
HLE::Clear();
}};

VideoBackendBase::PopulateBackendInfo();

if (!g_video_backend->Initialize(wsi))
{
PanicAlert("Failed to initialize video backend!");
return;
}
Common::ScopeGuard video_guard{[] { g_video_backend->Shutdown(); }};

// Render a single frame without anything on it to clear the screen.
// This avoids the game list being displayed while the core is finishing initializing.
g_renderer->BeginUIFrame();
g_renderer->EndUIFrame();

if (cpu_info.HTT)
SConfig::GetInstance().bDSPThread = cpu_info.num_cores > 4;
else
SConfig::GetInstance().bDSPThread = cpu_info.num_cores > 2;

if (!DSP::GetDSPEmulator()->Initialize(core_parameter.bWii, core_parameter.bDSPThread))
{
PanicAlert("Failed to initialize DSP emulation!");
return;
}

AudioCommon::InitSoundStream();
Common::ScopeGuard audio_guard{&AudioCommon::ShutdownSoundStream};

0 comments on commit e4e5069

Please sign in to comment.