Fixed a potential crash when mapping keys to Wiimote

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4703 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
ayuanx 2009-12-17 16:14:48 +00:00
parent 7d1fdb85f3
commit f255f08a99
3 changed files with 14 additions and 14 deletions

View File

@ -410,6 +410,7 @@ void WiimotePadConfigDialog::DoGetButtons(int _GetId)
int value; // Axis value or Hat value
int type; // Button type
int KeyPressed = 0;
int pressed = 0;
bool Succeed = false;
bool Stop = false; // Stop the timer
@ -426,8 +427,6 @@ void WiimotePadConfigDialog::DoGetButtons(int _GetId)
// Save the button Id
GetButtonWaitingID = _GetId;
GetButtonWaitingTimer = 0;
// Reset the key in case we happen to have an old one
g_Pressed = 0;
// Start the timer
#if wxUSE_TIMER
@ -446,7 +445,7 @@ void WiimotePadConfigDialog::DoGetButtons(int _GetId)
{
InputCommon::GetButton(
WiiMoteEmu::joyinfo[PadID].joy, PadID, WiiMoteEmu::joyinfo[PadID].NumButtons, WiiMoteEmu::joyinfo[PadID].NumAxes, WiiMoteEmu::joyinfo[PadID].NumHats,
g_Pressed, value, type, pressed, Succeed, Stop,
KeyPressed, value, type, pressed, Succeed, Stop,
LeftRight, Axis, XInput, Button, Hat, NoTriggerFilter);
}
@ -523,7 +522,7 @@ void WiimotePadConfigDialog::DoGetButtons(int _GetId)
}
// If we got a bad button
if(g_Pressed == -1)
if(KeyPressed == -1)
{
// Update text
SetButtonTextAll(_GetId, (char *)"PAD: -1");

View File

@ -120,6 +120,8 @@ WiimotePadConfigDialog::WiimotePadConfigDialog(wxWindow *parent, wxWindowID id,
m_UpdatePadTimer = new wxTimer(this, IDTM_UPDATE_PAD);
// Reset values
g_Pressed = 0;
ClickedButton = NULL;
GetButtonWaitingID = 0;
GetButtonWaitingTimer = 0;
@ -130,11 +132,10 @@ WiimotePadConfigDialog::WiimotePadConfigDialog(wxWindow *parent, wxWindowID id,
ControlsCreated = false;
Page = 0;
ClickedButton = NULL;
//g_Config.Load();
CreatePadGUIControls();
SetBackgroundColour(m_Notebook->GetBackgroundColour());
//SetBackgroundColour(m_Notebook->GetBackgroundColour());
// Set control values
UpdateGUI();
@ -195,10 +196,10 @@ void WiimotePadConfigDialog::OnKeyDown(wxKeyEvent& event)
}
}
#elif defined(HAVE_X11) && HAVE_X11
g_Pressed = InputCommon::wxCharCodeWXToX(g_Pressed);
InputCommon::XKeyToString(g_Pressed, keyStr);
int XKey = InputCommon::wxCharCodeWXToX(g_Pressed);
InputCommon::XKeyToString(XKey, keyStr);
SetButtonText(ClickedButton->GetId(), keyStr);
SaveKeyboardMapping(Page, ClickedButton->GetId(), g_Pressed);
SaveKeyboardMapping(Page, ClickedButton->GetId(), XKey);
#endif
}
m_ButtonMappingTimer->Stop();
@ -211,13 +212,13 @@ void WiimotePadConfigDialog::OnKeyDown(wxKeyEvent& event)
// Input button clicked
void WiimotePadConfigDialog::OnButtonClick(wxCommandEvent& event)
{
//DEBUG_LOG(WIIMOTE, "OnButtonClick: %i", g_Pressed);
if (m_ButtonMappingTimer->IsRunning()) return;
event.Skip();
// Don't allow space to start a new Press Key option, that will interfer with setting a key to space
if (g_Pressed == WXK_SPACE) { g_Pressed = 0; return; }
if (m_ButtonMappingTimer->IsRunning()) return;
// Create the button object
ClickedButton = (wxButton *)event.GetEventObject();
// Save old label so we can revert back

View File

@ -75,7 +75,7 @@ class WiimotePadConfigDialog : public wxDialog
DECLARE_EVENT_TABLE();
bool ControlsCreated;
int Page, g_Pressed, BoxW, BoxH;
int Page, BoxW, BoxH;
wxString OldLabel;
@ -300,7 +300,7 @@ class WiimotePadConfigDialog : public wxDialog
void OnButtonClick(wxCommandEvent& event);
// Configure buttons
int GetButtonWaitingID, GetButtonWaitingTimer;
int GetButtonWaitingID, GetButtonWaitingTimer, g_Pressed;
wxString GetButtonText(int id, int Page = -1);
};
extern WiimotePadConfigDialog *m_PadConfigFrame;