Merge pull request #2262 from OpenSpace/issue/2137

Issue/2137
This commit is contained in:
Malin E
2022-10-17 09:09:27 +02:00
committed by GitHub
2 changed files with 10 additions and 7 deletions

View File

@@ -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;

View File

@@ -28,6 +28,7 @@
#include <openspace/scripting/scriptengine.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/exception.h>
#include <algorithm>
#include <cmath>
#include <utility>
@@ -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<size_t>(nAxes), joystick->axisMapping.size());
++i)
{
AxisInformation t = joystick->axisMapping[i];
if (t.type == AxisType::None) {
continue;