Handle some undefined behavior regarding null pads

This commit is contained in:
Megamouse 2020-11-26 00:06:03 +01:00
parent ca9898e838
commit 9e352da052
8 changed files with 54 additions and 4 deletions

View File

@ -12,8 +12,42 @@ public:
return true; return true;
} }
void init_config(pad_config* /*cfg*/, const std::string& /*name*/) override void init_config(pad_config* cfg, const std::string& /*name*/) override
{ {
if (!cfg) return;
// This profile does not need a save location
cfg->cfg_name = "";
// Reset default button mapping
cfg->ls_left.def = "";
cfg->ls_down.def = "";
cfg->ls_right.def = "";
cfg->ls_up.def = "";
cfg->rs_left.def = "";
cfg->rs_down.def = "";
cfg->rs_right.def = "";
cfg->rs_up.def = "";
cfg->start.def = "";
cfg->select.def = "";
cfg->ps.def = "";
cfg->square.def = "";
cfg->cross.def = "";
cfg->circle.def = "";
cfg->triangle.def = "";
cfg->left.def = "";
cfg->down.def = "";
cfg->right.def = "";
cfg->up.def = "";
cfg->r1.def = "";
cfg->r2.def = "";
cfg->r3.def = "";
cfg->l1.def = "";
cfg->l2.def = "";
cfg->l3.def = "";
// Apply defaults
cfg->from_default();
} }
std::vector<std::string> ListDevices() override std::vector<std::string> ListDevices() override

View File

@ -244,6 +244,8 @@ std::shared_ptr<ds3_pad_handler::ds3_device> ds3_pad_handler::get_ds3_device(con
void ds3_pad_handler::init_config(pad_config* cfg, const std::string& name) void ds3_pad_handler::init_config(pad_config* cfg, const std::string& name)
{ {
if (!cfg) return;
// Set this profile's save location // Set this profile's save location
cfg->cfg_name = name; cfg->cfg_name = name;

View File

@ -136,6 +136,8 @@ ds4_pad_handler::ds4_pad_handler() : PadHandlerBase(pad_handler::ds4)
void ds4_pad_handler::init_config(pad_config* cfg, const std::string& name) void ds4_pad_handler::init_config(pad_config* cfg, const std::string& name)
{ {
if (!cfg) return;
// Set this profile's save location // Set this profile's save location
cfg->cfg_name = name; cfg->cfg_name = name;

View File

@ -49,6 +49,8 @@ evdev_joystick_handler::~evdev_joystick_handler()
void evdev_joystick_handler::init_config(pad_config* cfg, const std::string& name) void evdev_joystick_handler::init_config(pad_config* cfg, const std::string& name)
{ {
if (!cfg) return;
// Set this profile's save location // Set this profile's save location
cfg->cfg_name = name; cfg->cfg_name = name;

View File

@ -33,6 +33,8 @@ keyboard_pad_handler::keyboard_pad_handler()
void keyboard_pad_handler::init_config(pad_config* cfg, const std::string& name) void keyboard_pad_handler::init_config(pad_config* cfg, const std::string& name)
{ {
if (!cfg) return;
// Set this profile's save location // Set this profile's save location
cfg->cfg_name = name; cfg->cfg_name = name;

View File

@ -32,6 +32,8 @@ mm_joystick_handler::~mm_joystick_handler()
void mm_joystick_handler::init_config(pad_config* cfg, const std::string& name) void mm_joystick_handler::init_config(pad_config* cfg, const std::string& name)
{ {
if (!cfg) return;
// Set this profile's save location // Set this profile's save location
cfg->cfg_name = name; cfg->cfg_name = name;

View File

@ -83,6 +83,8 @@ xinput_pad_handler::~xinput_pad_handler()
void xinput_pad_handler::init_config(pad_config* cfg, const std::string& name) void xinput_pad_handler::init_config(pad_config* cfg, const std::string& name)
{ {
if (!cfg) return;
// Set this profile's save location // Set this profile's save location
cfg->cfg_name = name; cfg->cfg_name = name;

View File

@ -1027,8 +1027,8 @@ void pad_settings_dialog::UpdateLabels(bool is_reset)
entry.second.text = qstr(entry.second.key); entry.second.text = qstr(entry.second.key);
} }
// The button has to contain at least a space, because it would be square'ish otherwise // The button has to contain at least one character, because it would be square'ish otherwise
m_padButtons->button(entry.first)->setText(entry.second.text.isEmpty() ? QStringLiteral(" ") : entry.second.text); m_padButtons->button(entry.first)->setText(entry.second.text.isEmpty() ? QStringLiteral("-") : entry.second.text);
} }
} }
@ -1401,7 +1401,11 @@ void pad_settings_dialog::ChangeProfile()
} }
// Load new config // Load new config
m_handler_cfg.load(); if (m_handler->m_type != pad_handler::null && !m_handler_cfg.load())
{
cfg_log.error("Could not load pad config file '%s'", m_handler_cfg.cfg_name);
m_handler_cfg.from_default();
}
// Reload the buttons with the new handler and profile // Reload the buttons with the new handler and profile
ReloadButtons(); ReloadButtons();