Wiimote: Fixed crash that would occur if no gamepad was detected

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2211 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
John Peterson 2009-02-10 20:20:52 +00:00
parent c1214d2026
commit 5ba51ed789
3 changed files with 20 additions and 5 deletions

View File

@ -83,7 +83,7 @@ void Config::Load(bool ChangePad)
/* Prevent a crash from illegal access to joyinfo that will only have values for
the current amount of connected PadMapping */
if(WiiMoteEmu::PadMapping[i].ID >= SDL_NumJoysticks()) continue;
if(WiiMoteEmu::PadMapping[i].ID >= WiiMoteEmu::joyinfo.size()) continue;
// Create a section name
SectionName = WiiMoteEmu::joyinfo[WiiMoteEmu::PadMapping[i].ID].Name;
@ -146,7 +146,7 @@ void Config::Save(int Slot)
/* Save joypad specific settings. Check for "PadMapping[i].ID < SDL_NumJoysticks()" to
avoid reading a joyinfo that does't exist */
if(WiiMoteEmu::PadMapping[i].ID >= SDL_NumJoysticks()) continue;
if(WiiMoteEmu::PadMapping[i].ID >= WiiMoteEmu::joyinfo.size()) continue;
// Create a new section name after the joypad name
SectionName = WiiMoteEmu::joyinfo[WiiMoteEmu::PadMapping[i].ID].Name;

View File

@ -1143,9 +1143,21 @@ void ConfigDialog::UpdateGUI(int Slot)
m_UseRealWiimote[Page]->Enable((m_bEnableUseRealWiimote && g_RealWiiMotePresent && g_Config.bConnectRealWiimote) || !g_EmulatorRunning);
// Linux has no FindItem()
// Disable all pad items if no pads are detected
if(ControlsCreated)
{
bool PadEnabled = WiiMoteEmu::NumGoodPads != 0;
#ifdef _WIN32
for(int i = IDB_ANALOG_LEFT_X; i <= IDB_TRIGGER_R; i++) m_Notebook->FindItem(i)->Enable(PadEnabled);
m_Notebook->FindItem(IDC_JOYNAME)->Enable(PadEnabled);
m_Notebook->FindItem(ID_TRIGGER_TYPE)->Enable(PadEnabled);
#endif
}
// Disable all recording buttons
bool ActiveRecording = !(m_bWaitForRecording || m_bRecording);
#ifdef _WIN32
// Disable all recording buttons
for(int i = IDB_RECORD + 1; i < (IDB_RECORD + RECORDING_ROWS + 1); i++)
if(ControlsCreated) m_Notebook->FindItem(i)->Enable(!(m_bWaitForRecording || m_bRecording));
if(ControlsCreated) m_Notebook->FindItem(i)->Enable(ActiveRecording);
#endif
}

View File

@ -365,10 +365,13 @@ void SingleShake(u8 &_z, u8 &_y)
// ------------------------------------------
/* Tilting Wiimote with gamepad. We can guess that the game will calculate a Wiimote pitch and use it as a
measure of the tilting of the Wiimote. We are interested in this tilting range
90° to -90° */
90° to -90° */
// ---------------
void TiltWiimoteGamepad(u8 &_y, u8 &_z)
{
// Return if we have no pads
if (NumGoodPads == 0) return;
// Update the pad state
const int Page = 0;
WiiMoteEmu::GetJoyState(PadState[Page], PadMapping[Page], Page, joyinfo[PadMapping[Page].ID].NumButtons);