diff --git a/src/input/device_manager.cpp b/src/input/device_manager.cpp index 01e8c439f..d052470c9 100644 --- a/src/input/device_manager.cpp +++ b/src/input/device_manager.cpp @@ -69,7 +69,10 @@ GamePadDevice* DeviceManager::getGamePadFromIrrID(const int id) for(unsigned int i=0; i 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); @@ -195,6 +198,12 @@ bool DeviceManager::mapInputToPlayerAndAction( Input::InputType type, int device { GamePadDevice* gamepad = getGamePadFromIrrID(deviceID); + + if (gamepad == NULL) { + // Prevent null pointer crash + *player = NULL; + return false; + } if(m_assign_mode == NO_ASSIGN) { diff --git a/src/input/input_manager.cpp b/src/input/input_manager.cpp index c9eee4413..4b4960fb9 100644 --- a/src/input/input_manager.cpp +++ b/src/input/input_manager.cpp @@ -290,8 +290,16 @@ void InputManager::input(Input::InputType type, int deviceID, int btnID, int axi if(StateManager::get()->isGameState()) { // 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) { std::cerr << "Error, trying to process action for an unknown player\n"; @@ -376,6 +384,12 @@ bool InputManager::input(const SEvent& event) GamePadDevice* gp = getDeviceList()->getGamePadFromIrrID(event.JoystickEvent.Joystick); + if (gp == NULL) + { + // Prevent null pointer crash + return false; + } + for(int i=0; im_button_count; i++) { const bool isButtonPressed = event.JoystickEvent.IsButtonPressed(i);