Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions GCPad_Lib/src/GamepadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,17 @@ void GamepadManagerImpl::setGamepadDisconnectedCallback(GamepadDisconnectedCallb
}

void GamepadManagerImpl::updateAll() {
// Lock against the hotplug thread. Without this, updateAll() (called every
// frame from the polling thread) iterates gamepads_ and dereferences each
// device while the hotplug thread can simultaneously destroy a device in
// check_for_disconnected_devices() (gamepads_[i].reset()) — a data race and
// use-after-free that crashed the host whenever a pad dropped mid-frame.
// The hotplug thread already uses try_lock_for and simply skips a cycle if
// it can't acquire the lock, so this can never deadlock game launch.
std::lock_guard<std::timed_mutex> lock(mutex_);
for (auto& gamepad : gamepads_) {
if (gamepad) {
if (!gamepad->updateState()) {
}
gamepad->updateState();
}
}
}
Expand Down
Loading