diff --git a/joy/src/joy.cpp b/joy/src/joy.cpp index ce9e1631..a0368e3a 100644 --- a/joy/src/joy.cpp +++ b/joy/src/joy.cpp @@ -308,6 +308,7 @@ void Joy::handleJoyDeviceAdded(const SDL_Event & e) RCLCPP_WARN(get_logger(), "Failed to get the number of joysticks: %s", SDL_GetError()); return; } + bool matching_device_found = false; for (int i = 0; i < num_joysticks; ++i) { const char * name = SDL_JoystickNameForIndex(i); if (name == nullptr) { @@ -316,10 +317,17 @@ void Joy::handleJoyDeviceAdded(const SDL_Event & e) } if (std::string(name) == dev_name_) { // We found it! + matching_device_found = true; dev_id_ = i; break; } } + if (!matching_device_found) { + RCLCPP_WARN( + get_logger(), "Could not get joystick with name %s: %s", + dev_name_.c_str(), SDL_GetError()); + return; + } } if (e.jdevice.which != dev_id_) {