Controller patch by Bob Forder - thanks\!

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3789 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2009-07-31 23:50:40 +00:00
parent 4c3713789f
commit aceea4b120
2 changed files with 26 additions and 3 deletions

View File

@ -69,7 +69,10 @@ GamePadDevice* DeviceManager::getGamePadFromIrrID(const int id)
for(unsigned int i=0; i<m_gamepad_amount; i++) for(unsigned int i=0; i<m_gamepad_amount; i++)
{ {
if(m_gamepads[i].m_index == id) if(m_gamepads[i].m_index == id)
{
return m_gamepads.get(i); return m_gamepads.get(i);
}
} }
return NULL; return NULL;
} }
@ -89,7 +92,7 @@ bool DeviceManager::checkForGamePad(const int irr_id)
std::cout << " (checking...) I remember that gamepad #" << n << " is named " << m_gamepads[n].m_name.c_str() << std::endl; std::cout << " (checking...) I remember that gamepad #" << n << " is named " << m_gamepads[n].m_name.c_str() << std::endl;
// FIXME - don't check only name, but also number of axes and buttons? // FIXME - don't check only name, but also number of axes and buttons?
if(m_gamepads[n].m_name == name) if((m_gamepads[n].m_name == name) && (m_gamepads[n].m_index == irr_id))
{ {
std::cout << "--> that's the one currently connected\n"; std::cout << "--> that's the one currently connected\n";
m_gamepads[n].open(irr_id, m_gamepads[n].m_name, m_irrlicht_gamepads[irr_id].Axes, m_irrlicht_gamepads[irr_id].Buttons); m_gamepads[n].open(irr_id, m_gamepads[n].m_name, m_irrlicht_gamepads[irr_id].Axes, m_irrlicht_gamepads[irr_id].Buttons);
@ -196,6 +199,12 @@ bool DeviceManager::mapInputToPlayerAndAction( Input::InputType type, int device
GamePadDevice* gamepad = getGamePadFromIrrID(deviceID); GamePadDevice* gamepad = getGamePadFromIrrID(deviceID);
if (gamepad == NULL) {
// Prevent null pointer crash
*player = NULL;
return false;
}
if(m_assign_mode == NO_ASSIGN) if(m_assign_mode == NO_ASSIGN)
{ {
if(gamepad->hasBinding(type, btnID /* axis or button */, value, *player, action /* out */) ) if(gamepad->hasBinding(type, btnID /* axis or button */, value, *player, action /* out */) )

View File

@ -290,7 +290,15 @@ void InputManager::input(Input::InputType type, int deviceID, int btnID, int axi
if(StateManager::get()->isGameState()) if(StateManager::get()->isGameState())
{ {
// Find the corresponding PlayerKart from our ActivePlayer instance // Find the corresponding PlayerKart from our ActivePlayer instance
PlayerKart* pk = player->getKart(); PlayerKart* pk;
if (player == NULL)
{
// Prevent null pointer crash
return;
}
pk = player->getKart();
if (pk == NULL) if (pk == NULL)
{ {
@ -376,6 +384,12 @@ bool InputManager::input(const SEvent& event)
GamePadDevice* gp = getDeviceList()->getGamePadFromIrrID(event.JoystickEvent.Joystick); GamePadDevice* gp = getDeviceList()->getGamePadFromIrrID(event.JoystickEvent.Joystick);
if (gp == NULL)
{
// Prevent null pointer crash
return false;
}
for(int i=0; i<gp->m_button_count; i++) for(int i=0; i<gp->m_button_count; i++)
{ {
const bool isButtonPressed = event.JoystickEvent.IsButtonPressed(i); const bool isButtonPressed = event.JoystickEvent.IsButtonPressed(i);