From: terencehill Date: Sun, 9 Feb 2025 00:26:28 +0000 (+0100) Subject: Menu: don't set focusedItem to values lower than -1 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=6c9f93c54b2b44d35e1bada7f586fe028015e996;p=xonotic%2Fxonotic-data.pk3dir.git 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. --- 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));