Skip to content

Commit

Permalink
Merge pull request #15 from hymerman/master
Browse files Browse the repository at this point in the history
Protect against null pointer dereference in case GetProcAddress fails
  • Loading branch information
speps committed Mar 17, 2015
2 parents 4e3a79c + 7b8413b commit 406e642
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions XInputInterface/GamePad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,22 @@ namespace
DWORD XInputGamePadGetState(DWORD dwUserIndex, XINPUT_STATE* pState)
{
gXInputLoader.ensureLoaded();
return gXInputLoader.mGetState(dwUserIndex, pState);
if(gXInputLoader.mGetState != NULL)
{
return gXInputLoader.mGetState(dwUserIndex, pState);
}
else
{
return ERROR_DEVICE_NOT_CONNECTED;
}
}

void XInputGamePadSetState(DWORD dwUserIndex, float leftMotor, float rightMotor)
{
gXInputLoader.ensureLoaded();
XINPUT_VIBRATION vibration = { (int)(leftMotor * 65535), (int)(rightMotor * 65535) };
gXInputLoader.mSetState(dwUserIndex, &vibration);
}
if(gXInputLoader.mSetState != NULL)
{
XINPUT_VIBRATION vibration = { (int)(leftMotor * 65535), (int)(rightMotor * 65535) };
gXInputLoader.mSetState(dwUserIndex, &vibration);
}
}

0 comments on commit 406e642

Please sign in to comment.