Input/Qt: Check if gui callbacks are nullptr

This commit is contained in:
Megamouse 2020-07-04 13:18:45 +02:00
parent ea4cc0b395
commit f1b1c9053c
3 changed files with 47 additions and 18 deletions

View file

@ -328,7 +328,11 @@ void PadHandlerBase::get_next_button_press(const std::string& pad_id, const pad_
const auto status = update_connection(device);
if (status == connection::disconnected)
return fail_callback(pad_id);
{
if (fail_callback)
fail_callback(pad_id);
return;
}
else if (status == connection::no_data)
return;
@ -373,10 +377,13 @@ void PadHandlerBase::get_next_button_press(const std::string& pad_id, const pad_
const auto preview_values = get_preview_values(data);
const auto battery_level = get_battery_level(pad_id);
if (pressed_button.first > 0)
return callback(pressed_button.first, pressed_button.second, pad_id, battery_level, preview_values);
else
return callback(0, "", pad_id, battery_level, preview_values);
if (callback)
{
if (pressed_button.first > 0)
return callback(pressed_button.first, pressed_button.second, pad_id, battery_level, preview_values);
else
return callback(0, "", pad_id, battery_level, preview_values);
}
return;
}

View file

@ -281,7 +281,11 @@ void evdev_joystick_handler::get_next_button_press(const std::string& padId, con
// Get our evdev device
auto device = get_evdev_device(padId);
if (!device || device->device == nullptr)
return fail_callback(padId);
{
if (fail_callback)
fail_callback(padId);
return;
}
libevdev* dev = device->device;
// Try to query the latest event from the joystick.
@ -320,7 +324,11 @@ void evdev_joystick_handler::get_next_button_press(const std::string& padId, con
// return if nothing new has happened. ignore this to get the current state for blacklist
if (!get_blacklist && ret < 0)
return callback(0, "", padId, 0, preview_values);
{
if (callback)
callback(0, "", padId, 0, preview_values);
return;
}
std::pair<u16, std::string> pressed_button = { 0, "" };
@ -401,10 +409,13 @@ void evdev_joystick_handler::get_next_button_press(const std::string& padId, con
return;
}
if (pressed_button.first > 0)
return callback(pressed_button.first, pressed_button.second, padId, 0, preview_values);
else
return callback(0, "", padId, 0, preview_values);
if (callback)
{
if (pressed_button.first > 0)
return callback(pressed_button.first, pressed_button.second, padId, 0, preview_values);
else
return callback(0, "", padId, 0, preview_values);
}
}
// https://github.com/dolphin-emu/dolphin/blob/master/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp

View file

@ -182,7 +182,11 @@ void mm_joystick_handler::get_next_button_press(const std::string& padId, const
blacklist.clear();
if (!Init())
return fail_callback(padId);
{
if (fail_callback)
fail_callback(padId);
return;
}
static std::string cur_pad = "";
static int id = -1;
@ -194,7 +198,9 @@ void mm_joystick_handler::get_next_button_press(const std::string& padId, const
if (id < 0)
{
input_log.error("MMJOY get_next_button_press for device [%s] failed with id = %d", padId, id);
return fail_callback(padId);
if (fail_callback)
fail_callback(padId);
return;
}
}
@ -210,7 +216,9 @@ void mm_joystick_handler::get_next_button_press(const std::string& padId, const
{
case JOYERR_UNPLUGGED:
{
return fail_callback(padId);
if (fail_callback)
fail_callback(padId);
return;
}
case JOYERR_NOERROR:
{
@ -309,10 +317,13 @@ void mm_joystick_handler::get_next_button_press(const std::string& padId, const
preview_values[5] = data[find_key(buttons[9])] - data[find_key(buttons[8])];
}
if (pressed_button.first > 0)
return callback(pressed_button.first, pressed_button.second, padId, 0, preview_values);
else
return callback(0, "", padId, 0, preview_values);
if (callback)
{
if (pressed_button.first > 0)
return callback(pressed_button.first, pressed_button.second, padId, 0, preview_values);
else
return callback(0, "", padId, 0, preview_values);
}
break;
}