onepad: safely dispatch rumble action

Fix onepad crashes
This commit is contained in:
Gregory Hainaut 2015-11-10 08:12:20 +01:00
parent d62d2abf59
commit ac0e40a2b7
3 changed files with 21 additions and 6 deletions

View File

@ -23,12 +23,27 @@ void GamePad::EnumerateGamePads(vector<GamePad*>& vgamePad)
JoystickInfo::EnumerateJoysticks(vgamePad); JoystickInfo::EnumerateJoysticks(vgamePad);
#endif #endif
} }
void GamePad::UpdateReleaseState() void GamePad::UpdateReleaseState()
{ {
#ifdef SDL_BUILD #ifdef SDL_BUILD
JoystickInfo::UpdateReleaseState(); JoystickInfo::UpdateReleaseState();
#endif #endif
} }
/**
* Safely dispatch to the Rumble method above
**/
void GamePad::DoRumble(int type, int pad)
{
u32 id = conf->get_joyid(pad);
if (GamePadIdWithinBounds(id)) {
GamePad* gamePad = s_vgamePad[id];
if (gamePad)
gamePad->Rumble(type, pad);
}
}
/** /**
* Update state of every attached devices * Update state of every attached devices
**/ **/

View File

@ -43,6 +43,10 @@ class GamePad
* Rumble will differ according to type which is either 0(small motor) or 1(big motor) * Rumble will differ according to type which is either 0(small motor) or 1(big motor)
**/ **/
virtual void Rumble(int type,int pad){return;} virtual void Rumble(int type,int pad){return;}
/**
* Safely dispatch to the Rumble method above
**/
static void DoRumble(int type, int pad);
virtual bool Init(int id){return false;} // opens a handle and gets information virtual bool Init(int id){return false;} // opens a handle and gets information

View File

@ -418,9 +418,7 @@ u8 _PADpoll(u8 value)
if (padVibF[curPad][2] != vib_small) if (padVibF[curPad][2] != vib_small)
{ {
padVibF[curPad][2] = vib_small; padVibF[curPad][2] = vib_small;
// SetDeviceForceS (padVibC[curPad], vib_small); GamePad::DoRumble(0, curPad);
GamePad* gamePad = s_vgamePad[conf->get_joyid(curPad)];
gamePad->Rumble(0,curPad);
} }
/* Big Motor */ /* Big Motor */
@ -429,9 +427,7 @@ u8 _PADpoll(u8 value)
if (padVibF[curPad][3] != vib_big) if (padVibF[curPad][3] != vib_big)
{ {
padVibF[curPad][3] = vib_big; padVibF[curPad][3] = vib_big;
// SetDeviceForceB (padVibC[curPad], vib_big); GamePad::DoRumble(1, curPad);
GamePad* gamePad = s_vgamePad[conf->get_joyid(curPad)];
gamePad->Rumble(1,curPad);
} }
return padID[curPad]; return padID[curPad];