From d0f85cba41e7a32c6270147c9df24c7dbf43ae4c Mon Sep 17 00:00:00 2001 From: Arian Behvandnejad Date: Sat, 4 May 2013 13:40:35 +0430 Subject: [PATCH] Fixed issue #959: Joystick configuration lost if not plugged in --- src/control/joystickkeyboardcontroller.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/control/joystickkeyboardcontroller.cpp b/src/control/joystickkeyboardcontroller.cpp index de414fadcaa..6c9e9c06dff 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) {