From b425f86121c8c9f3b4a510e522d03e432677dcea Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Thu, 10 Jan 2019 09:02:38 -0600 Subject: ControllerInterface: Allow hotplug callbacks to be unregistered and don't reload the entire config from the ini file on hotplug, just update the control references. This should fix a crash on shutdown on Android. --- Source/Core/InputCommon/InputConfig.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'Source/Core/InputCommon/InputConfig.cpp') diff --git a/Source/Core/InputCommon/InputConfig.cpp b/Source/Core/InputCommon/InputConfig.cpp index dfc677d70a..65cfdef086 100644 --- a/Source/Core/InputCommon/InputConfig.cpp +++ b/Source/Core/InputCommon/InputConfig.cpp @@ -147,6 +147,21 @@ std::size_t InputConfig::GetControllerCount() const return m_controllers.size(); } +void InputConfig::RegisterHotplugCallback() +{ + // Update control references on all controllers + // as configured devices may have been added or removed. + m_hotplug_callback_handle = g_controller_interface.RegisterDevicesChangedCallback([this] { + for (auto& controller : m_controllers) + controller->UpdateReferences(g_controller_interface); + }); +} + +void InputConfig::UnregisterHotplugCallback() +{ + g_controller_interface.UnregisterDevicesChangedCallback(m_hotplug_callback_handle); +} + bool InputConfig::IsControllerControlledByGamepadDevice(int index) const { if (static_cast(index) >= m_controllers.size()) -- cgit v1.2.3