From 38fa501a0868f720182f2f6325a45399bdeb4132 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sat, 28 Jan 2023 23:42:56 -0800 Subject: [PATCH] Qt: Fix controller hotplugging --- src/platform/qt/input/SDLInputDriver.cpp | 16 +++++++++++----- src/platform/qt/input/SDLInputDriver.h | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/platform/qt/input/SDLInputDriver.cpp b/src/platform/qt/input/SDLInputDriver.cpp index ca9e30b25..5b68462d1 100644 --- a/src/platform/qt/input/SDLInputDriver.cpp +++ b/src/platform/qt/input/SDLInputDriver.cpp @@ -89,6 +89,7 @@ QString SDLInputDriver::currentProfile() const { } void SDLInputDriver::loadConfiguration(ConfigController* config) { + m_config = config; mSDLEventsLoadConfig(&s_sdlEvents, config->input()); if (!m_playerAttached) { m_playerAttached = mSDLAttachPlayer(&s_sdlEvents, &m_sdlPlayer); @@ -126,7 +127,7 @@ mRotationSource* SDLInputDriver::rotationSource() { bool SDLInputDriver::update() { - if (!m_playerAttached || !m_sdlPlayer.joystick) { + if (!m_playerAttached) { return false; } @@ -148,6 +149,9 @@ QList SDLInputDriver::connectedGamepads() const { #if SDL_VERSION_ATLEAST(2, 0, 0) void SDLInputDriver::updateGamepads() { + if (m_config) { + mSDLUpdateJoysticks(&s_sdlEvents, m_config->input()); + } for (int i = 0; i < m_gamepads.size(); ++i) { if (m_gamepads.at(i)->updateIndex()) { continue; @@ -160,10 +164,12 @@ void SDLInputDriver::updateGamepads() { }); for (size_t i = 0, j = 0; i < SDL_JoystickListSize(&s_sdlEvents.joysticks); ++i) { - std::shared_ptr gamepad = m_gamepads.at(j); - if (gamepad->m_index == i) { - ++j; - continue; + if ((ssize_t) j < m_gamepads.size()) { + std::shared_ptr gamepad = m_gamepads.at(j); + if (gamepad->m_index == i) { + ++j; + continue; + } } m_gamepads.append(std::make_shared(this, i)); } diff --git a/src/platform/qt/input/SDLInputDriver.h b/src/platform/qt/input/SDLInputDriver.h index 09f4b9555..0ca2f4030 100644 --- a/src/platform/qt/input/SDLInputDriver.h +++ b/src/platform/qt/input/SDLInputDriver.h @@ -62,6 +62,7 @@ public: mRotationSource* rotationSource() override; private: + ConfigController* m_config = nullptr; InputController* m_controller; mSDLPlayer m_sdlPlayer{}; bool m_playerAttached = false;