From 6c9f93c54b2b44d35e1bada7f586fe028015e996 Mon Sep 17 00:00:00 2001 From: terencehill Date: Sun, 9 Feb 2025 01:26:28 +0100 Subject: [PATCH] Menu: don't set focusedItem to values lower than -1 It fixes this subtle bug: QC crash by "dragging" any item in Settings > Game's ListBox (the thing with HUD, Messages, etc.) above the top of the list (even though it's an immutable list, so dragging should do nothing other than change the selection). It was due to XonoticRegisteredSettingsList_focusedItemChangeNotify considering focusedItems < -1 as valid items. For extra safety I made so that XonoticRegisteredSettingsList_focusedItemChangeNotify considers any focusedItem < 0 invalid anyway (like XonoticGametypeList_focusedItemChangeNotify). I also removed a duplicated focusedItemChangeNotify declaration. --- qcsrc/menu/item/listbox.qc | 2 +- qcsrc/menu/xonotic/dialog_settings_game.qc | 2 +- qcsrc/menu/xonotic/dialog_settings_game.qh | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/qcsrc/menu/item/listbox.qc b/qcsrc/menu/item/listbox.qc index 021bc95ce..9b47482f5 100644 --- a/qcsrc/menu/item/listbox.qc +++ b/qcsrc/menu/item/listbox.qc @@ -251,7 +251,7 @@ void ListBox_setFocusedItem(entity me, int item) { float focusedItem_save = me.focusedItem; - me.focusedItem = (item < me.nItems) ? item : -1; + me.focusedItem = (item >= 0 && item < me.nItems) ? item : -1; if (focusedItem_save != me.focusedItem) { me.focusedItemChangeNotify(me); diff --git a/qcsrc/menu/xonotic/dialog_settings_game.qc b/qcsrc/menu/xonotic/dialog_settings_game.qc index b617d4915..5605f8c82 100644 --- a/qcsrc/menu/xonotic/dialog_settings_game.qc +++ b/qcsrc/menu/xonotic/dialog_settings_game.qc @@ -46,7 +46,7 @@ METHOD(XonoticRegisteredSettingsList, drawListBoxItem, void(entity this, int i, METHOD(XonoticRegisteredSettingsList, focusedItemChangeNotify, void(entity this)) { - if (this.focusedItem == -1 || !this.source) + if (this.focusedItem < 0 || !this.source) { clearTooltip(this); return; diff --git a/qcsrc/menu/xonotic/dialog_settings_game.qh b/qcsrc/menu/xonotic/dialog_settings_game.qh index c0965c232..3a4a36b1d 100644 --- a/qcsrc/menu/xonotic/dialog_settings_game.qh +++ b/qcsrc/menu/xonotic/dialog_settings_game.qh @@ -22,7 +22,6 @@ CLASS(XonoticRegisteredSettingsList, XonoticListBox) ATTRIB(XonoticRegisteredSettingsList, source, DataSource); ATTRIB(XonoticRegisteredSettingsList, onChange, void(entity, entity)); ATTRIB(XonoticRegisteredSettingsList, onChangeEntity, entity); - METHOD(XonoticRegisteredSettingsList, focusedItemChangeNotify, void(entity)); METHOD(XonoticRegisteredSettingsList, drawListBoxItem, void(entity this, int i, vector absSize, bool isSelected, bool isFocused)); METHOD(XonoticRegisteredSettingsList, focusedItemChangeNotify, void(entity this)); METHOD(XonoticRegisteredSettingsList, refilter, void(entity this)); -- 2.39.5