Skip to content

Commit d4b5c64

Browse files
committed
joystick, controller, fix mistake, so that controllers were not able to be removed from an internal array due to not using JoystickLikeInput but JoystickInput
1 parent 2eb5f98 commit d4b5c64

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/input/joystick_input.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,8 @@ void input::JoyStickInputManager::discover_devices(std::vector<std::unique_ptr<I
114114
const auto allow_background_events_result = SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
115115

116116
if (allow_background_events_result != SDL_TRUE) {
117+
// this is non fatal, so not returning
117118
spdlog::warn("Failed to set the JOYSTICK_ALLOW_BACKGROUND_EVENTS hint: {}", SDL_GetError());
118-
119-
return;
120119
}
121120

122121
const auto mappings_file = utils::get_assets_folder() / "mappings" / "gamecontrollerdb.txt";
@@ -233,7 +232,13 @@ void input::JoyStickInputManager::add_new_device(
233232
return;
234233
}
235234

235+
spdlog::info(
236+
"Added new device ({}): {}", type == input::JoystickLikeType::Joystick ? "joystick" : "controller",
237+
joystick->get()->name()
238+
);
239+
236240
inputs.push_back(std::move(joystick.value()));
241+
237242
} else {
238243
spdlog::warn(
239244
"Failed to add newly attached {}: {}",
@@ -250,7 +255,8 @@ void input::JoyStickInputManager::remove_device(
250255
) {
251256
for (auto it = inputs.cbegin(); it != inputs.cend(); it++) {
252257

253-
if (const auto joystick_input = utils::is_child_class<input::JoystickInput>(*it); joystick_input.has_value()) {
258+
if (const auto joystick_input = utils::is_child_class<input::JoystickLikeInput>(*it);
259+
joystick_input.has_value()) {
254260

255261
if (joystick_input.value()->instance_id() == instance_id) {
256262
//TODO(Totto): if we use this joystick as game input we have to notify the user about it,and pause the game, until he is inserted again
@@ -261,8 +267,9 @@ void input::JoyStickInputManager::remove_device(
261267
}
262268
}
263269

264-
spdlog::warn(fmt::format(
265-
"Failed to remove removed {} from internal input vector (maybe he was not recognized in the first place)",
270+
//this happens way to often, since Sdl outputs both SDL_JOYDEVICEREMOVED and SDL_CONTROLLERDEVICEREMOVED at the same time, in case of a controller, so the second time, this is reached :(
271+
spdlog::debug(fmt::format(
272+
"Failed to remove removed {} from internal input vector",
266273
type == input::JoystickLikeType::Joystick ? "joystick" : "controller"
267274
));
268275
}

0 commit comments

Comments
 (0)