diff --git a/apps/OpenSpace/main.cpp b/apps/OpenSpace/main.cpp index 4b50f87617..3ef64126fc 100644 --- a/apps/OpenSpace/main.cpp +++ b/apps/OpenSpace/main.cpp @@ -216,21 +216,20 @@ void checkJoystickStatus() { state.isConnected = true; state.name = glfwGetJoystickName(i); - std::fill(state.axes.begin(), state.axes.end(), 0.f); - std::fill(state.buttons.begin(), state.buttons.end(), JoystickAction::Idle); - // Check axes and buttons glfwGetJoystickAxes(i, &state.nAxes); glfwGetJoystickButtons(i, &state.nButtons); + state.axes.resize(state.nAxes); + state.buttons.resize(state.nButtons); + + std::fill(state.axes.begin(), state.axes.end(), 0.f); + std::fill(state.buttons.begin(), state.buttons.end(), JoystickAction::Idle); } const float* axes = glfwGetJoystickAxes(i, &state.nAxes); - state.axes.resize(state.nAxes); std::memcpy(state.axes.data(), axes, state.nAxes * sizeof(float)); const unsigned char* buttons = glfwGetJoystickButtons(i, &state.nButtons); - state.buttons.resize(state.nButtons); - for (int j = 0; j < state.nButtons; ++j) { const bool currentlyPressed = buttons[j] == GLFW_PRESS; diff --git a/src/interaction/joystickcamerastates.cpp b/src/interaction/joystickcamerastates.cpp index 93260f2945..cd1be5bca7 100644 --- a/src/interaction/joystickcamerastates.cpp +++ b/src/interaction/joystickcamerastates.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -63,7 +64,10 @@ void JoystickCameraStates::updateStateFromInput( } int nAxes = joystickInputStates.numAxes(joystickInputState.name); - for (int i = 0; i < nAxes; ++i) { + for (int i = 0; + i < std::min(static_cast(nAxes), joystick->axisMapping.size()); + ++i) + { AxisInformation t = joystick->axisMapping[i]; if (t.type == AxisType::None) { continue;