fix: desbordamiento de indice en el vector de gamecontrollers en la clase input

This commit is contained in:
2024-07-07 10:13:49 +02:00
parent 9f91b5cf18
commit 9a91e6b6ec
2 changed files with 12 additions and 1 deletions

View File

@@ -21,6 +21,7 @@ Input::Input(std::string file)
verbose = true; verbose = true;
enabled = true; enabled = true;
// Listado de los inputs usados para jugar, excluyendo botones para la interfaz
gameInputs.clear(); gameInputs.clear();
gameInputs.push_back(input_fire_left); gameInputs.push_back(input_fire_left);
gameInputs.push_back(input_fire_center); gameInputs.push_back(input_fire_center);
@@ -30,6 +31,7 @@ Input::Input(std::string file)
gameInputs.push_back(input_left); gameInputs.push_back(input_left);
gameInputs.push_back(input_right); gameInputs.push_back(input_right);
// Listado de los inputs para jugar que utilizan botones, ni palancas ni crucetas
buttonInputs.clear(); buttonInputs.clear();
buttonInputs.push_back(input_fire_left); buttonInputs.push_back(input_fire_left);
buttonInputs.push_back(input_fire_center); buttonInputs.push_back(input_fire_center);
@@ -61,7 +63,7 @@ void Input::bindGameControllerButton(inputs_e input, SDL_GameControllerButton bu
// Comprueba si un input esta activo // Comprueba si un input esta activo
bool Input::checkInput(inputs_e input, bool repeat, int device, int index) bool Input::checkInput(inputs_e input, bool repeat, int device, int index)
{ {
if (!enabled) if (!enabled || index >= numGamepads)
{ {
return false; return false;
} }

View File

@@ -7,6 +7,15 @@
#ifndef INPUT_H #ifndef INPUT_H
#define INPUT_H #define INPUT_H
/*
connectedControllers es un vector donde estan todos los mandos encontrados [0 .. n]
checkInput requiere de un indice para comprobar las pulsaciónes de un controlador en concreto [0 .. n]
device contiene el tipo de dispositivo a comprobar:
INPUT_USE_KEYBOARD solo mirará el teclado
INPUT_USE_GAMECONTROLLER solo mirará el controlador especificado (Si no se especifica, el primero)
INPUT_USE_ANY mirará tanto el teclado como el PRIMER controlador
*/
enum inputs_e enum inputs_e
{ {
// Inputs obligatorios // Inputs obligatorios