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
This commit is contained in:
John Peterson 2009-02-17 11:16:59 +00:00
parent 9ed368b35a
commit 12a869304c
3 changed files with 13 additions and 11 deletions

View File

@ -55,7 +55,7 @@ void Config::Load(bool ChangePad)
// Default controls // Default controls
#ifdef _WIN32 #ifdef _WIN32
int WmA = 65, WmB = 65, int WmA = 65, WmB = 66,
Wm1 = 49, Wm2 = 50, Wm1 = 49, Wm2 = 50,
WmP = 80, WmM = 77, WmH = 72, WmP = 80, WmM = 77, WmH = 72,
WmL = 37, WmR = 39, WmU = 38, WmD = 40, // Regular directional keys 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 // Don't update this when we are loading settings from the ConfigBox
if(!ChangePad) 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(), "DeviceID", &WiiMoteEmu::PadMapping[i].ID, 0);
iniFile.Get(SectionName.c_str(), "Enabled", &WiiMoteEmu::PadMapping[i].enabled, true); 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);
// =================== // ===================
// ================================================================== // ==================================================================

View File

@ -204,7 +204,9 @@ void ConfigDialog::SaveButtonMapping(int controller, bool DontChangeId, int From
// Replace "" with "-1" in the GUI controls // Replace "" with "-1" in the GUI controls
ToBlank(false); 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 <No Gamepad Detected>, or a gamepad name, not a
a blank selection. */
if(!DontChangeId) WiiMoteEmu::PadMapping[controller].ID = m_Joyname[FromSlot]->GetSelection(); if(!DontChangeId) WiiMoteEmu::PadMapping[controller].ID = m_Joyname[FromSlot]->GetSelection();
// Set enabled or disable status // Set enabled or disable status
if(FromSlot == controller) WiiMoteEmu::PadMapping[controller].enabled = true; //m_Joyattach[FromSlot]->GetValue(); // Only enable one 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_AnalogTriggerL[FromSlot]->GetValue().ToLong(&value); WiiMoteEmu::PadMapping[controller].Axis.Tl = value;
m_AnalogTriggerR[FromSlot]->GetValue().ToLong(&value); WiiMoteEmu::PadMapping[controller].Axis.Tr = 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", //Console::Print("WiiMoteEmu::PadMapping[%i].ID = %i, m_Joyname[%i]->GetSelection() = %i\n",
// controller, WiiMoteEmu::PadMapping[controller].deadzone, FromSlot, m_ComboDeadZone[FromSlot]->GetSelection()); // controller, WiiMoteEmu::PadMapping[controller].ID, FromSlot, m_Joyname[FromSlot]->GetSelection());
// Replace "-1" with "" // Replace "-1" with ""
ToBlank(); ToBlank();
@ -608,10 +610,10 @@ void ConfigDialog::PadGetStatus()
// Get physical device status // Get physical device status
int PhysicalDevice = WiiMoteEmu::PadMapping[Page].ID; int PhysicalDevice = WiiMoteEmu::PadMapping[Page].ID;
int TriggerType = WiiMoteEmu::PadMapping[Page].triggertype; int TriggerType = WiiMoteEmu::PadMapping[Page].triggertype;
// Check that Dolphin is in focus, otherwise don't update the pad status // Check that Dolphin is in focus, otherwise don't update the pad status
//if (IsFocus()) //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);
////////////////////////////////////// //////////////////////////////////////

View File

@ -48,8 +48,9 @@ bool StrangeHack = true;
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯ // ¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void ConfigBox::PadGetStatus() void ConfigBox::PadGetStatus()
{ {
// Return if it's not detected /* Return if it's not detected. The ID should never be less than zero here, it can only be that
if(PadMapping[notebookpage].ID >= SDL_NumJoysticks()) 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_TStatusIn[notebookpage]->SetLabel(wxT("Not connected"));
m_TStatusOut[notebookpage]->SetLabel(wxT("Not connected")); m_TStatusOut[notebookpage]->SetLabel(wxT("Not connected"));