From 1b34248ef60457600ad3cbc65183a2fb8bbdd5a0 Mon Sep 17 00:00:00 2001 From: bmdhacks Date: Sun, 10 Aug 2025 17:05:37 -0700 Subject: [PATCH 1/4] fix a crash in skill selection dialog due to uninitialized controller data --- apps/openmw/mwgui/class.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwgui/class.cpp b/apps/openmw/mwgui/class.cpp index 9573d22377..c7189bc340 100644 --- a/apps/openmw/mwgui/class.cpp +++ b/apps/openmw/mwgui/class.cpp @@ -1022,6 +1022,8 @@ namespace MWGui SelectSkillDialog::SelectSkillDialog() : WindowModal("openmw_chargen_select_skill.layout") , mSkillId(ESM::Skill::Block) + , mControllerFocus(0) + , mNumSkillsPerSpecialization{} { // Centre dialog center(); @@ -1063,7 +1065,6 @@ namespace MWGui if (Settings::gui().mControllerMenus) { - mControllerFocus = 0; if (mSkillButtons.size() > 0) mSkillButtons[0]->setStateSelected(true); From 80a29ab57b906f1830576e6e8f947810af5e0e4e Mon Sep 17 00:00:00 2001 From: bmdhacks Date: Mon, 11 Aug 2025 17:08:17 -0700 Subject: [PATCH 2/4] bulk initialize controller focus to zero --- apps/openmw/mwgui/class.cpp | 2 +- apps/openmw/mwgui/class.h | 0 apps/openmw/mwgui/class.hpp | 8 ++++---- apps/openmw/mwgui/itemchargeview.hpp | 2 +- apps/openmw/mwgui/levelupdialog.hpp | 2 +- apps/openmw/mwgui/mapwindow.hpp | 2 +- apps/openmw/mwgui/merchantrepair.hpp | 2 +- apps/openmw/mwgui/messagebox.hpp | 2 +- apps/openmw/mwgui/quickkeysmenu.cpp | 2 -- apps/openmw/mwgui/quickkeysmenu.hpp | 6 +++--- apps/openmw/mwgui/review.hpp | 2 +- apps/openmw/mwgui/spellbuyingwindow.hpp | 2 +- apps/openmw/mwgui/spellcreationdialog.hpp | 2 +- apps/openmw/mwgui/trainingwindow.hpp | 2 +- apps/openmw/mwgui/travelwindow.hpp | 2 +- 15 files changed, 18 insertions(+), 20 deletions(-) create mode 100644 apps/openmw/mwgui/class.h diff --git a/apps/openmw/mwgui/class.cpp b/apps/openmw/mwgui/class.cpp index c7189bc340..dc823e2f15 100644 --- a/apps/openmw/mwgui/class.cpp +++ b/apps/openmw/mwgui/class.cpp @@ -1021,8 +1021,8 @@ namespace MWGui SelectSkillDialog::SelectSkillDialog() : WindowModal("openmw_chargen_select_skill.layout") - , mSkillId(ESM::Skill::Block) , mControllerFocus(0) + , mSkillId(ESM::Skill::Block) , mNumSkillsPerSpecialization{} { // Centre dialog diff --git a/apps/openmw/mwgui/class.h b/apps/openmw/mwgui/class.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/apps/openmw/mwgui/class.hpp b/apps/openmw/mwgui/class.hpp index 5a769e15bd..6db9a9dc34 100644 --- a/apps/openmw/mwgui/class.hpp +++ b/apps/openmw/mwgui/class.hpp @@ -51,7 +51,7 @@ namespace MWGui MyGUI::TextBox* mText; MyGUI::Widget* mButtonBar; std::vector mButtons; - size_t mControllerFocus; + size_t mControllerFocus = 0; }; // Lets the player choose between 3 ways of creating a class @@ -218,7 +218,7 @@ namespace MWGui void onAttributeClicked(Widgets::MWAttributePtr _sender); void onCancelClicked(MyGUI::Widget* _sender); bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; - size_t mControllerFocus; + size_t mControllerFocus = 0; std::vector mAttributeButtons; private: @@ -252,7 +252,7 @@ namespace MWGui void onSkillClicked(Widgets::MWSkillPtr _sender); void onCancelClicked(MyGUI::Widget* _sender); bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; - size_t mControllerFocus; + size_t mControllerFocus = 0; std::vector mSkillButtons; private: @@ -353,7 +353,7 @@ namespace MWGui Widgets::MWSkillPtr mAffectedSkill; bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; - size_t mControllerFocus; + size_t mControllerFocus = 0; }; } #endif diff --git a/apps/openmw/mwgui/itemchargeview.hpp b/apps/openmw/mwgui/itemchargeview.hpp index 73bf9c3de2..fd0388d83a 100644 --- a/apps/openmw/mwgui/itemchargeview.hpp +++ b/apps/openmw/mwgui/itemchargeview.hpp @@ -75,7 +75,7 @@ namespace MWGui MyGUI::ScrollView* mScrollView; DisplayMode mDisplayMode; - int mControllerFocus; + int mControllerFocus = 0; void updateControllerFocus(int prevFocus, int newFocus); }; } diff --git a/apps/openmw/mwgui/levelupdialog.hpp b/apps/openmw/mwgui/levelupdialog.hpp index 70bd2839f2..5176d1866b 100644 --- a/apps/openmw/mwgui/levelupdialog.hpp +++ b/apps/openmw/mwgui/levelupdialog.hpp @@ -53,7 +53,7 @@ namespace MWGui bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; std::vector mAttributeButtons; - size_t mControllerFocus; + size_t mControllerFocus = 0; }; } diff --git a/apps/openmw/mwgui/mapwindow.hpp b/apps/openmw/mwgui/mapwindow.hpp index 9a474e8170..379141fb61 100644 --- a/apps/openmw/mwgui/mapwindow.hpp +++ b/apps/openmw/mwgui/mapwindow.hpp @@ -225,7 +225,7 @@ namespace MWGui MyGUI::Button* mDeleteButton; bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; - int mControllerFocus; + int mControllerFocus = 0; }; class MapWindow : public MWGui::WindowPinnableBase, public LocalMapBase, public NoDrop diff --git a/apps/openmw/mwgui/merchantrepair.hpp b/apps/openmw/mwgui/merchantrepair.hpp index 28fb2a7c3c..119258f7ad 100644 --- a/apps/openmw/mwgui/merchantrepair.hpp +++ b/apps/openmw/mwgui/merchantrepair.hpp @@ -27,7 +27,7 @@ namespace MWGui MWWorld::Ptr mActor; - size_t mControllerFocus; + size_t mControllerFocus = 0; protected: void onMouseWheel(MyGUI::Widget* _sender, int _rel); diff --git a/apps/openmw/mwgui/messagebox.hpp b/apps/openmw/mwgui/messagebox.hpp index 98eb69cc69..d48223d1a4 100644 --- a/apps/openmw/mwgui/messagebox.hpp +++ b/apps/openmw/mwgui/messagebox.hpp @@ -116,7 +116,7 @@ namespace MWGui int mButtonPressed; size_t mDefaultFocus; bool mImmediate; - size_t mControllerFocus; + size_t mControllerFocus = 0; }; } diff --git a/apps/openmw/mwgui/quickkeysmenu.cpp b/apps/openmw/mwgui/quickkeysmenu.cpp index 782949b99a..a7c408f1f9 100644 --- a/apps/openmw/mwgui/quickkeysmenu.cpp +++ b/apps/openmw/mwgui/quickkeysmenu.cpp @@ -40,7 +40,6 @@ namespace MWGui , mKey(std::vector(10)) , mSelected(nullptr) , mActivated(nullptr) - , mControllerFocus(0) { getWidget(mOkButton, "OKButton"); getWidget(mInstructionLabel, "InstructionLabel"); @@ -506,7 +505,6 @@ namespace MWGui QuickKeysMenuAssign::QuickKeysMenuAssign(QuickKeysMenu* parent) : WindowModal("openmw_quickkeys_menu_assign.layout") , mParent(parent) - , mControllerFocus(0) { getWidget(mLabel, "Label"); getWidget(mItemButton, "ItemButton"); diff --git a/apps/openmw/mwgui/quickkeysmenu.hpp b/apps/openmw/mwgui/quickkeysmenu.hpp index 11648cdb40..30cd893c84 100644 --- a/apps/openmw/mwgui/quickkeysmenu.hpp +++ b/apps/openmw/mwgui/quickkeysmenu.hpp @@ -75,7 +75,7 @@ namespace MWGui void assignItem(MWWorld::Ptr item); bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; - size_t mControllerFocus; + size_t mControllerFocus = 0; }; class QuickKeysMenuAssign : public WindowModal @@ -93,7 +93,7 @@ namespace MWGui QuickKeysMenu* mParent; bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; - int mControllerFocus; + int mControllerFocus = 0; }; class MagicSelectionDialog : public WindowModal @@ -114,7 +114,7 @@ namespace MWGui void onModelIndexSelected(SpellModel::ModelIndex index); bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; - int mControllerFocus; + int mControllerFocus = 0; }; } diff --git a/apps/openmw/mwgui/review.hpp b/apps/openmw/mwgui/review.hpp index cd3fc594a7..78d88887db 100644 --- a/apps/openmw/mwgui/review.hpp +++ b/apps/openmw/mwgui/review.hpp @@ -104,7 +104,7 @@ namespace MWGui // 0 = Name, 1 = Race, 2 = Class, 3 = BirthSign, 4 = Back, 5 = OK std::vector mButtons; - int mControllerFocus; + int mControllerFocus = 0; }; } #endif diff --git a/apps/openmw/mwgui/spellbuyingwindow.hpp b/apps/openmw/mwgui/spellbuyingwindow.hpp index a53b57cc09..ad47749228 100644 --- a/apps/openmw/mwgui/spellbuyingwindow.hpp +++ b/apps/openmw/mwgui/spellbuyingwindow.hpp @@ -58,7 +58,7 @@ namespace MWGui private: static bool sortSpells(const ESM::Spell* left, const ESM::Spell* right); bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; - size_t mControllerFocus; + size_t mControllerFocus = 0; }; } diff --git a/apps/openmw/mwgui/spellcreationdialog.hpp b/apps/openmw/mwgui/spellcreationdialog.hpp index f2c440d305..8d96a9727d 100644 --- a/apps/openmw/mwgui/spellcreationdialog.hpp +++ b/apps/openmw/mwgui/spellcreationdialog.hpp @@ -94,7 +94,7 @@ namespace MWGui bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; void updateControllerFocus(int prevFocus, int newFocus); - int mControllerFocus; + int mControllerFocus = 0; std::vector mButtons; }; diff --git a/apps/openmw/mwgui/trainingwindow.hpp b/apps/openmw/mwgui/trainingwindow.hpp index f44c5524f5..c6c9cdf5c8 100644 --- a/apps/openmw/mwgui/trainingwindow.hpp +++ b/apps/openmw/mwgui/trainingwindow.hpp @@ -55,7 +55,7 @@ namespace MWGui TimeAdvancer mTimeAdvancer; bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; - size_t mControllerFocus; + size_t mControllerFocus = 0; }; } diff --git a/apps/openmw/mwgui/travelwindow.hpp b/apps/openmw/mwgui/travelwindow.hpp index c0002b805b..4b155e4535 100644 --- a/apps/openmw/mwgui/travelwindow.hpp +++ b/apps/openmw/mwgui/travelwindow.hpp @@ -42,7 +42,7 @@ namespace MWGui private: bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; - size_t mControllerFocus; + size_t mControllerFocus = 0; }; } From 30bd014bd7eb8d44d8976520f64492ba8ded7c15 Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Thu, 14 Aug 2025 13:43:46 +0300 Subject: [PATCH 3/4] Some controller focus initialization cleanup --- apps/openmw/mwgui/class.cpp | 5 ----- apps/openmw/mwgui/class.h | 0 apps/openmw/mwgui/class.hpp | 4 ++-- 3 files changed, 2 insertions(+), 7 deletions(-) delete mode 100644 apps/openmw/mwgui/class.h diff --git a/apps/openmw/mwgui/class.cpp b/apps/openmw/mwgui/class.cpp index dc823e2f15..5a03e269cf 100644 --- a/apps/openmw/mwgui/class.cpp +++ b/apps/openmw/mwgui/class.cpp @@ -383,7 +383,6 @@ namespace MWGui InfoBoxDialog::InfoBoxDialog() : WindowModal("openmw_infobox.layout") - , mControllerFocus(0) { getWidget(mTextBox, "TextBox"); getWidget(mText, "Text"); @@ -525,7 +524,6 @@ namespace MWGui : WindowModal("openmw_chargen_create_class.layout") , mAffectedAttribute(nullptr) , mAffectedSkill(nullptr) - , mControllerFocus(2) { // Centre dialog center(); @@ -962,7 +960,6 @@ namespace MWGui if (Settings::gui().mControllerMenus) { - mControllerFocus = 0; if (mAttributeButtons.size() > 0) mAttributeButtons[0]->setStateSelected(true); @@ -1021,9 +1018,7 @@ namespace MWGui SelectSkillDialog::SelectSkillDialog() : WindowModal("openmw_chargen_select_skill.layout") - , mControllerFocus(0) , mSkillId(ESM::Skill::Block) - , mNumSkillsPerSpecialization{} { // Centre dialog center(); diff --git a/apps/openmw/mwgui/class.h b/apps/openmw/mwgui/class.h deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/apps/openmw/mwgui/class.hpp b/apps/openmw/mwgui/class.hpp index 6db9a9dc34..3755ab5f58 100644 --- a/apps/openmw/mwgui/class.hpp +++ b/apps/openmw/mwgui/class.hpp @@ -257,7 +257,7 @@ namespace MWGui private: ESM::RefId mSkillId; - std::array mNumSkillsPerSpecialization; + std::array mNumSkillsPerSpecialization{}; void selectNextColumn(int direction); }; @@ -353,7 +353,7 @@ namespace MWGui Widgets::MWSkillPtr mAffectedSkill; bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; - size_t mControllerFocus = 0; + size_t mControllerFocus = 2; }; } #endif From cae36d6eec68c14e0018653972ca4acdf982e08e Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Thu, 14 Aug 2025 13:33:20 +0200 Subject: [PATCH 4/4] Add remaining default initialisations flagged by Coverity --- apps/openmw/mwgui/itemview.hpp | 2 +- apps/openmw/mwgui/journalwindow.hpp | 5 ++--- apps/openmw/mwgui/windowmanagerimp.hpp | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwgui/itemview.hpp b/apps/openmw/mwgui/itemview.hpp index 6243618abc..1e2ab8817f 100644 --- a/apps/openmw/mwgui/itemview.hpp +++ b/apps/openmw/mwgui/itemview.hpp @@ -54,7 +54,7 @@ namespace MWGui MyGUI::ScrollView* mScrollView; int mItemCount = 0; - int mRows; + int mRows = 1; int mControllerFocus = 0; bool mControllerActiveWindow; void updateControllerFocus(int prevFocus, int newFocus); diff --git a/apps/openmw/mwgui/journalwindow.hpp b/apps/openmw/mwgui/journalwindow.hpp index 6122bf70c7..472065d565 100644 --- a/apps/openmw/mwgui/journalwindow.hpp +++ b/apps/openmw/mwgui/journalwindow.hpp @@ -25,16 +25,15 @@ namespace MWGui std::shared_ptr model, bool questList, ToUTF8::FromType encoding); /// destroy this instance of the JournalWindow implementation - virtual ~JournalWindow() {} + virtual ~JournalWindow() = default; /// show/hide the journal window void setVisible(bool newValue) override = 0; std::string_view getWindowIdForLua() const override { return "Journal"; } - size_t mIndexRowCount; - std::vector mButtons; + size_t mIndexRowCount = 1; size_t mSelectedQuest = 0; size_t mSelectedIndex = 0; void moveSelectedIndex(int offset); diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp index 81294d3cd4..991e3c1c00 100644 --- a/apps/openmw/mwgui/windowmanagerimp.hpp +++ b/apps/openmw/mwgui/windowmanagerimp.hpp @@ -511,7 +511,7 @@ namespace MWGui std::vector mGuiModes; // The active window for controller mode for each GUI mode. std::map mActiveControllerWindows; - bool mControllerTooltip; + bool mControllerTooltip = false; void reapplyActiveControllerWindow();