From: Arian Behvandnejad Date: Sat, 4 May 2013 09:10:35 +0000 (+0430) Subject: Fixed issue #959: Joystick configuration lost if not plugged in X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=d0f85cba41e7a32c6270147c9df24c7dbf43ae4c;p=supertux.git Fixed issue #959: Joystick configuration lost if not plugged in --- diff --git a/src/control/joystickkeyboardcontroller.cpp b/src/control/joystickkeyboardcontroller.cpp index de414fadc..6c9e9c06d 100644 --- a/src/control/joystickkeyboardcontroller.cpp +++ b/src/control/joystickkeyboardcontroller.cpp @@ -239,8 +239,10 @@ JoystickKeyboardController::read(const Reader& lisp) continue; } + bool js_available = joysticks.size() > 0; + if (map->get("button", button)) { - if(button < 0 || button >= max_joybuttons) { + if(js_available && (button < 0 || button >= max_joybuttons)) { log_info << "Invalid button '" << button << "' in buttonmap" << std::endl; continue; } @@ -248,7 +250,7 @@ JoystickKeyboardController::read(const Reader& lisp) } if (map->get("axis", axis)) { - if (axis == 0 || abs(axis) > max_joyaxis) { + if (js_available && (axis == 0 || abs(axis) > max_joyaxis)) { log_info << "Invalid axis '" << axis << "' in axismap" << std::endl; continue; } @@ -256,7 +258,8 @@ JoystickKeyboardController::read(const Reader& lisp) } if (map->get("hat", hat)) { - if (hat != SDL_HAT_UP && + if (js_available && + hat != SDL_HAT_UP && hat != SDL_HAT_DOWN && hat != SDL_HAT_LEFT && hat != SDL_HAT_RIGHT) {