MMJOYSTICK: fix nullpointer crash in GetMMJOYDevice

This commit is contained in:
Megamouse 2018-07-22 11:52:56 +02:00
parent d13e71eeb8
commit 8b693ed7bb
3 changed files with 14 additions and 9 deletions

View File

@ -753,7 +753,7 @@ bool ds4_pad_handler::Init()
}
if (controllers.size() == 0)
LOG_ERROR(HLE, "[DS4] No controllers found!");
LOG_WARNING(HLE, "[DS4] No controllers found!");
else
LOG_SUCCESS(HLE, "[DS4] Controllers found: %d", controllers.size());

View File

@ -91,7 +91,7 @@ bool mm_joystick_handler::Init()
{
MMJOYDevice dev;
if (GetMMJOYDevice(i, dev) == false)
if (GetMMJOYDevice(i, &dev) == false)
continue;
m_devices.emplace(i, dev);
@ -226,7 +226,7 @@ void mm_joystick_handler::ThreadProc()
if (last_connection_status[i] == false)
{
if (GetMMJOYDevice(m_dev->device_id, *m_dev) == false)
if (GetMMJOYDevice(m_dev->device_id, m_dev.get()) == false)
continue;
LOG_SUCCESS(HLE, "MMJOY Device %d reconnected.", m_dev->device_id);
pad->m_port_status |= CELL_PAD_STATUS_CONNECTED;
@ -558,8 +558,13 @@ int mm_joystick_handler::GetIDByName(const std::string& name)
return -1;
}
bool mm_joystick_handler::GetMMJOYDevice(int index, MMJOYDevice& dev)
bool mm_joystick_handler::GetMMJOYDevice(int index, MMJOYDevice* dev)
{
if (!dev)
{
return false;
}
JOYINFOEX js_info;
JOYCAPS js_caps;
js_info.dwSize = sizeof(js_info);
@ -574,10 +579,10 @@ bool mm_joystick_handler::GetMMJOYDevice(int index, MMJOYDevice& dev)
LOG_NOTICE(GENERAL, "Joystick nr.%d found. Driver: %s", index, drv);
dev.device_id = index;
dev.device_name = m_name_string + std::to_string(index);
dev.device_info = js_info;
dev.device_caps = js_caps;
dev->device_id = index;
dev->device_name = m_name_string + std::to_string(index);
dev->device_info = js_info;
dev->device_caps = js_caps;
return true;
}

View File

@ -115,7 +115,7 @@ private:
void TranslateButtonPress(u64 keyCode, bool& pressed, u16& val, bool ignore_threshold = false) override;
std::unordered_map<u64, u16> GetButtonValues(const JOYINFOEX& js_info, const JOYCAPS& js_caps);
int GetIDByName(const std::string& name);
bool GetMMJOYDevice(int index, MMJOYDevice& dev);
bool GetMMJOYDevice(int index, MMJOYDevice* dev);
bool is_init = false;
u32 m_supported_joysticks = 0;