From 12a869304cf3b030190916c157e35465a75730d7 Mon Sep 17 00:00:00 2001 From: John Peterson Date: Tue, 17 Feb 2009 11:16:59 +0000 Subject: [PATCH] Emulated Wiimote: Fixed a bug that would make PadMapping[0].ID = -1, that would lead to a segmentation fault in Linux when we tried to access joyinfo[-1] git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2287 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Plugins/Plugin_Wiimote/Src/Config.cpp | 7 +++---- Source/Plugins/Plugin_Wiimote/Src/ConfigGamepad.cpp | 12 +++++++----- .../Plugin_nJoy_SDL/Src/GUI/ConfigAdvanced.cpp | 5 +++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Source/Plugins/Plugin_Wiimote/Src/Config.cpp b/Source/Plugins/Plugin_Wiimote/Src/Config.cpp index 3df45669e3..920a241006 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/Config.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/Config.cpp @@ -55,7 +55,7 @@ void Config::Load(bool ChangePad) // Default controls #ifdef _WIN32 - int WmA = 65, WmB = 65, + int WmA = 65, WmB = 66, Wm1 = 49, Wm2 = 50, WmP = 80, WmM = 77, WmH = 72, WmL = 37, WmR = 39, WmU = 38, WmD = 40, // Regular directional keys @@ -117,12 +117,11 @@ void Config::Load(bool ChangePad) // Don't update this when we are loading settings from the ConfigBox if(!ChangePad) { + /* This pad Id could possibly be higher than the number of pads that are connected, + but we check later, when needed, that that is not the case */ iniFile.Get(SectionName.c_str(), "DeviceID", &WiiMoteEmu::PadMapping[i].ID, 0); iniFile.Get(SectionName.c_str(), "Enabled", &WiiMoteEmu::PadMapping[i].enabled, true); } - - // Check if the pad ID is within the range of avaliable pads - if (WiiMoteEmu::PadMapping[i].ID > (WiiMoteEmu::NumPads - 1)) WiiMoteEmu::PadMapping[i].ID = (WiiMoteEmu::NumPads - 1); // =================== // ================================================================== diff --git a/Source/Plugins/Plugin_Wiimote/Src/ConfigGamepad.cpp b/Source/Plugins/Plugin_Wiimote/Src/ConfigGamepad.cpp index 2438c44476..b706ed22b4 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/ConfigGamepad.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/ConfigGamepad.cpp @@ -204,7 +204,9 @@ void ConfigDialog::SaveButtonMapping(int controller, bool DontChangeId, int From // Replace "" with "-1" in the GUI controls ToBlank(false); - // Set physical device Id + /* Set physical device Id. GetSelection() should never be -1 here so we don't check that it's zero or higher. If it's possible that it can be + -1 that's a bug that should be fixed. Because the m_Joyname[] combo box should always show , or a gamepad name, not a + a blank selection. */ if(!DontChangeId) WiiMoteEmu::PadMapping[controller].ID = m_Joyname[FromSlot]->GetSelection(); // Set enabled or disable status if(FromSlot == controller) WiiMoteEmu::PadMapping[controller].enabled = true; //m_Joyattach[FromSlot]->GetValue(); // Only enable one @@ -228,8 +230,8 @@ void ConfigDialog::SaveButtonMapping(int controller, bool DontChangeId, int From m_AnalogTriggerL[FromSlot]->GetValue().ToLong(&value); WiiMoteEmu::PadMapping[controller].Axis.Tl = value; m_AnalogTriggerR[FromSlot]->GetValue().ToLong(&value); WiiMoteEmu::PadMapping[controller].Axis.Tr = value; - //Console::Print("WiiMoteEmu::PadMapping[%i].deadzone = %i, m_ComboDeadZone[%i]->GetSelection() = %i\n", - // controller, WiiMoteEmu::PadMapping[controller].deadzone, FromSlot, m_ComboDeadZone[FromSlot]->GetSelection()); + //Console::Print("WiiMoteEmu::PadMapping[%i].ID = %i, m_Joyname[%i]->GetSelection() = %i\n", + // controller, WiiMoteEmu::PadMapping[controller].ID, FromSlot, m_Joyname[FromSlot]->GetSelection()); // Replace "-1" with "" ToBlank(); @@ -608,10 +610,10 @@ void ConfigDialog::PadGetStatus() // Get physical device status int PhysicalDevice = WiiMoteEmu::PadMapping[Page].ID; int TriggerType = WiiMoteEmu::PadMapping[Page].triggertype; - + // Check that Dolphin is in focus, otherwise don't update the pad status //if (IsFocus()) - WiiMoteEmu::GetJoyState(WiiMoteEmu::PadState[Page], WiiMoteEmu::PadMapping[Page], Page, WiiMoteEmu::joyinfo[WiiMoteEmu::PadMapping[Page].ID].NumButtons); + WiiMoteEmu::GetJoyState(WiiMoteEmu::PadState[Page], WiiMoteEmu::PadMapping[Page], Page, WiiMoteEmu::joyinfo.at(WiiMoteEmu::PadMapping[Page].ID).NumButtons); ////////////////////////////////////// diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigAdvanced.cpp b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigAdvanced.cpp index 093ce67f72..2958cb824d 100644 --- a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigAdvanced.cpp +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigAdvanced.cpp @@ -48,8 +48,9 @@ bool StrangeHack = true; // ŻŻŻŻŻŻŻŻŻŻŻŻŻŻ void ConfigBox::PadGetStatus() { - // Return if it's not detected - if(PadMapping[notebookpage].ID >= SDL_NumJoysticks()) + /* Return if it's not detected. The ID should never be less than zero here, it can only be that + because of a manual ini file change, but we make that check anway. */ + if(PadMapping[notebookpage].ID >= 0 && PadMapping[notebookpage].ID >= SDL_NumJoysticks()) { m_TStatusIn[notebookpage]->SetLabel(wxT("Not connected")); m_TStatusOut[notebookpage]->SetLabel(wxT("Not connected"));