diff --git a/Quake/menu.c b/Quake/menu.c index b02379f6c..db43d91e5 100644 --- a/Quake/menu.c +++ b/Quake/menu.c @@ -3382,7 +3382,11 @@ static int M_Options_GetSelected (void) static qboolean M_Options_IsEnabled (int index) { + if ((unsigned int) index >= (unsigned int)optionsmenu.list.numitems) + return false; index += optionsmenu.first_item; + if ((unsigned int) index >= countof (options_names)) + return false; if (index > GPAD_OPTIONS_FIRST && index < GPAD_OPTIONS_FIRST + GPAD_OPTIONS_ITEMS && !joy_enable.value) return false; if (M_Options_IsGyroId (index) && !IN_HasGyro ()) @@ -3395,10 +3399,7 @@ static qboolean M_Options_IsSelectable (int index) if (!M_Options_IsEnabled (index)) return false; index += optionsmenu.first_item; - return - (unsigned int) index < countof (options_names) && - options_names[index][0] != '\0' - ; + return options_names[index][0] != '\0'; } static qboolean M_Options_Match (int index) @@ -3461,6 +3462,10 @@ void M_Options_Init (enum m_state_e state) M_List_ClearSearch (&optionsmenu.list); + // If the cursor is on an inactive item, move it to the next active one + if (!M_Options_IsSelectable (optionsmenu.list.cursor)) + M_List_SelectNextActive (&optionsmenu.list, optionsmenu.list.cursor, 1, true); + M_Options_UpdateLayout (); }