Skip to content

Commit

Permalink
Refactor controller initialization steps
Browse files Browse the repository at this point in the history
Use string.append() where possible, see if this helps with a rare RetroPie crash
  • Loading branch information
midwan committed Nov 15, 2023
1 parent 143d270 commit 013178c
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/osdep/amiberry_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -945,18 +945,17 @@ static int init_joystick()
}
else
{
TCHAR tmp[100];
for (uae_s16 b = 0; b < did->buttons; b++)
{
did->buttonsort[b] = b;
did->buttonmappings[b] = b;
did->buttonname[b] = "Button " + std::to_string(b);
did->buttonname[b] = std::string("Button ").append(std::to_string(b));
}
for (uae_s16 a = 0; a < did->axles; a++)
{
did->axissort[a] = a;
did->axismappings[a] = a;
did->axisname[a] = "Axis " + std::to_string(a);
did->axisname[a] = std::string("Axis ").append(std::to_string(a));
if (a == SDL_CONTROLLER_AXIS_LEFTX || a == SDL_CONTROLLER_AXIS_RIGHTX)
did->axistype[a] = AXISTYPE_POV_X;
else if (a == SDL_CONTROLLER_AXIS_LEFTY || a == SDL_CONTROLLER_AXIS_RIGHTY)
Expand All @@ -970,9 +969,9 @@ static int init_joystick()
fixbuttons(did);
fixthings(did);

auto retroarch_config_file = string(controllers_path);
const auto sanitized_name = sanitize_retroarch_name(did->joystick_name);
retroarch_config_file += sanitized_name + ".cfg";
auto retroarch_config_file = std::string(controllers_path);
auto sanitized_name = sanitize_retroarch_name(did->joystick_name);
retroarch_config_file += sanitized_name.append(".cfg") ;
write_log("Joystick name: '%s', sanitized to: '%s'\n", did->joystick_name.c_str(), sanitized_name.c_str());

if (my_existsfile2(retroarch_config_file.c_str()))
Expand All @@ -993,7 +992,7 @@ static int init_joystick()
int found_player = -1;
for (auto p = 1; p < 5; p++)
{
const int pindex = find_retroarch(("input_player" + to_string(p) + "_joypad_index").c_str(), retroarch_file);
const int pindex = find_retroarch((std::string("input_player").append(to_string(p)).append(std::string("_joypad_index"))).c_str(), retroarch_file);
if (pindex == i)
{
found_player = p;
Expand Down

0 comments on commit 013178c

Please sign in to comment.