From cebb4d84f2a8021a5df2ff2a9d31eba16e1cb5e5 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Tue, 11 Oct 2016 12:41:29 -0700 Subject: ControllerInterface: clear devices before shutting down backends The SDL backend faults if it tries to close a joystick after SDL_Quit has been called. --- .../ControllerInterface/ControllerInterface.cpp | 24 ++++++++++++---------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index c6f250a157..13873ac2dd 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -102,6 +102,19 @@ void ControllerInterface::Shutdown() if (!m_is_init) return; + { + std::lock_guard lk(m_devices_mutex); + + for (const auto& d : m_devices) + { + // Set outputs to ZERO before destroying device + for (ciface::Core::Device::Output* o : d->Outputs()) + o->SetState(0); + } + + m_devices.clear(); + } + #ifdef CIFACE_USE_XINPUT ciface::XInput::DeInit(); #endif @@ -126,17 +139,6 @@ void ControllerInterface::Shutdown() ciface::evdev::Shutdown(); #endif - std::lock_guard lk(m_devices_mutex); - - for (const auto& d : m_devices) - { - // Set outputs to ZERO before destroying device - for (ciface::Core::Device::Output* o : d->Outputs()) - o->SetState(0); - } - - m_devices.clear(); - m_is_init = false; } -- cgit v1.2.3 From 3e69d066f5e9ad0a1097d806c656035398bbb7bc Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Sun, 16 Oct 2016 13:39:05 -0700 Subject: ControllerInterface: replace Reinitialize with RefreshDevices The SDL backend crashes when you close a joystick after SDL_Quit has been called. Some backends don't need to be shutdown and re-initialized everytime, we can just ask to enumerate devices again. --- .../ControllerInterface/ControllerInterface.cpp | 45 ++++++++++++++++++---- 1 file changed, 37 insertions(+), 8 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index 13873ac2dd..635284d2c5 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -55,41 +55,70 @@ void ControllerInterface::Initialize(void* const hwnd) m_hwnd = hwnd; #ifdef CIFACE_USE_DINPUT - ciface::DInput::Init((HWND)hwnd); +// nothing needed #endif #ifdef CIFACE_USE_XINPUT ciface::XInput::Init(); #endif #ifdef CIFACE_USE_XLIB - ciface::XInput2::Init(hwnd); +// nothing needed #endif #ifdef CIFACE_USE_OSX ciface::OSX::Init(hwnd); - ciface::Quartz::Init(hwnd); +// nothing needed for Quartz #endif #ifdef CIFACE_USE_SDL ciface::SDL::Init(); #endif #ifdef CIFACE_USE_ANDROID - ciface::Android::Init(); +// nothing needed #endif #ifdef CIFACE_USE_EVDEV ciface::evdev::Init(); #endif #ifdef CIFACE_USE_PIPES - ciface::Pipes::Init(); +// nothing needed #endif m_is_init = true; + RefreshDevices(); } -void ControllerInterface::Reinitialize() +void ControllerInterface::RefreshDevices() { if (!m_is_init) return; - Shutdown(); - Initialize(m_hwnd); + { + std::lock_guard lk(m_devices_mutex); + m_devices.clear(); + } + +#ifdef CIFACE_USE_DINPUT + ciface::DInput::PopulateDevices(reinterpret_cast(m_hwnd)); +#endif +#ifdef CIFACE_USE_XINPUT + ciface::XInput::PopulateDevices(); +#endif +#ifdef CIFACE_USE_XLIB + ciface::XInput2::PopulateDevices(m_hwnd); +#endif +#ifdef CIFACE_USE_OSX + ciface::OSX::PopulateDevices(m_hwnd); + ciface::Quartz::PopulateDevices(m_hwnd); +#endif +#ifdef CIFACE_USE_SDL + ciface::SDL::PopulateDevices(); +#endif +#ifdef CIFACE_USE_ANDROID + ciface::Android::PopulateDevices(); +#endif +#ifdef CIFACE_USE_EVDEV + ciface::evdev::PopulateDevices(); +#endif +#ifdef CIFACE_USE_PIPES + ciface::Pipes::PopulateDevices(); +#endif } // -- cgit v1.2.3