commit 8c282de8f96d29384d515248d8a1cd63a3f53177
Author: Alexandre-Xavier Labonté-Lamoureux <alexandrexavier@live.ca>
AuthorDate: Sat Nov 12 23:08:19 2016 -0500
Commit: Alexandre-Xavier Labonté-Lamoureux <alexandrexavier@live.ca>
CommitDate: Sat Nov 12 23:08:19 2016 -0500
Fix number of joystick buttons so Chocolate-Setup doesn't crash
This fixes #799. Made the size of 'static int *all_joystick_buttons[]'
explicit so the compiler will know if there is something wrong.
---
src/i_joystick.c | 2 +-
src/i_joystick.h | 2 +-
src/m_config.c | 7 +++++++
src/setup/joystick.c | 2 +-
src/setup/txt_joybinput.c | 6 +++---
5 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/src/i_joystick.c b/src/i_joystick.c
index 76ef3b78..2ef27f13 100644
--- a/src/i_joystick.c
+++ b/src/i_joystick.c
@@ -68,7 +68,7 @@ static int joystick_strafe_invert = 0;
// Virtual to physical button joystick button mapping. By default this
// is a straight mapping.
static int joystick_physical_buttons[NUM_VIRTUAL_BUTTONS] = {
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
};
void I_ShutdownJoystick(void)
diff --git a/src/i_joystick.h b/src/i_joystick.h
index b8815e21..1c9744f5 100644
--- a/src/i_joystick.h
+++ b/src/i_joystick.h
@@ -22,7 +22,7 @@
// Number of "virtual" joystick buttons defined in configuration files.
// This needs to be at least as large as the number of different key
// bindings supported by the higher-level game code (joyb* variables).
-#define NUM_VIRTUAL_BUTTONS 10
+#define NUM_VIRTUAL_BUTTONS 11
// If this bit is set in a configuration file axis value, the axis is
// not actually a joystick axis, but instead is a "button axis". This
diff --git a/src/m_config.c b/src/m_config.c
index c74832db..5619926e 100644
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -1032,6 +1032,13 @@ static default_t extra_defaults_list[] =
CONFIG_VARIABLE_INT(joystick_physical_button9),
+ //!
+ // The physical joystick button that corresponds to joystick
+ // virtual button #10.
+ //
+
+ CONFIG_VARIABLE_INT(joystick_physical_button10),
+
//!
// Joystick virtual button to make the player strafe left.
//
diff --git a/src/setup/joystick.c b/src/setup/joystick.c
index 58bd3c95..e4880344 100644
--- a/src/setup/joystick.c
+++ b/src/setup/joystick.c
@@ -81,7 +81,7 @@ static int joystick_strafe_invert = 0;
// Virtual to physical mapping.
int joystick_physical_buttons[NUM_VIRTUAL_BUTTONS] = {
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
};
static txt_button_t *joystick_button;
diff --git a/src/setup/txt_joybinput.c b/src/setup/txt_joybinput.c
index b8dbb121..d0c3926b 100644
--- a/src/setup/txt_joybinput.c
+++ b/src/setup/txt_joybinput.c
@@ -44,7 +44,7 @@ extern int joystick_physical_buttons[NUM_VIRTUAL_BUTTONS];
// button that the user wants to use for firing. We do this so that
// the menus work (the game code is hard coded to interpret
// button #0 = select menu item, button #1 = go back to previous menu).
-static int *all_joystick_buttons[] =
+static int *all_joystick_buttons[NUM_VIRTUAL_BUTTONS] =
{
&joybfire,
&joybuse,
@@ -72,7 +72,7 @@ static int PhysicalForVirtualButton(int vbutton)
}
// Get the virtual button number for the given variable, ie. the
-// variable's index in all_joystick_buttons[].
+// variable's index in all_joystick_buttons[NUM_VIRTUAL_BUTTONS].
static int VirtualButtonForVariable(int *variable)
{
int i;
@@ -91,7 +91,7 @@ static int VirtualButtonForVariable(int *variable)
// Rearrange joystick button configuration to be in "canonical" form:
// each joyb* variable should have a value equal to its index in
-// all_joystick_buttons[] above.
+// all_joystick_buttons[NUM_VIRTUAL_BUTTONS] above.
static void CanonicalizeButtons(void)
{
int new_mapping[NUM_VIRTUAL_BUTTONS];