Skip to content

Fix "Save Main Configuration" saving to wrong file after "Load Configuration"#18771

Merged
LibretroAdmin merged 1 commit intolibretro:masterfrom
RJNY:rjny/save-main-config-fix
Feb 25, 2026
Merged

Fix "Save Main Configuration" saving to wrong file after "Load Configuration"#18771
LibretroAdmin merged 1 commit intolibretro:masterfrom
RJNY:rjny/save-main-config-fix

Conversation

@RJNY
Copy link
Contributor

@RJNY RJNY commented Feb 25, 2026

Description

After using "Load Configuration" to switch to a different .cfg file,
"Save Main Configuration" writes to the loaded file instead of the
original startup config. This is because config_replace() updates
RARCH_PATH_CONFIG to point at the newly loaded file.

The previous CMD_EVENT_MENU_SAVE_MAIN_CONFIG handler called
open_default_config_file() as a side effect to reset the path, but
discarded the returned config_file_t*, leaking it on every save.

Fix:

  • Record the startup config path into a new RARCH_PATH_CONFIG_DEFAULT
    slot right after config_load() in retroarch_parse_input_and_config()
  • In the save handler, temporarily swap RARCH_PATH_CONFIG to the
    default path before saving, then restore the previous value
  • Make open_default_config_file() static (no longer called outside
    configuration.c) and remove its declaration from configuration.h

Steps to reproduce

  1. Launch RetroArch
  2. Main Menu > Configuration File > Load Configuration > pick a different .cfg
  3. Main Menu > Configuration File > Save Main Configuration
  4. Save goes to the loaded file, not the default config

Testing

Android (aarch64, Pixel) and macOS (Metal).

  • After "Load Configuration", "Save Main" now writes to the startup config (not the loaded file)
  • "Save Main" without prior "Load Configuration" still works
  • config_save_on_exit still writes to the loaded file after config_replace()
  • Config overrides unaffected

Relates to #16491

@cmitu
Copy link
Contributor

cmitu commented Feb 25, 2026

How does this work when RetroArch is started with a specific config file via the CLI parameter --config ? Does it save to the loaded file (which --config points to) or tries to save to the 'default' location ?

To be honest, as a user, if I load a configuration file, then modify options and use 'Save Configuration' I'd expect the save to go to the loaded file rather than a default configuration.

@hizzlekizzle
Copy link
Collaborator

@sonninnos @warmenhoven

I figured you guys would be most likely to have familiarity with this behavior and potential pitfalls.

@sonninnos
Copy link
Collaborator

sonninnos commented Feb 25, 2026

"Save Main" is working on Windows as expected after loading any other than default, so if it does not do that with all platforms and this fixes it, then good.

To be honest, as a user, if I load a configuration file, then modify options and use 'Save Configuration' I'd expect the save to go to the loaded file rather than a default configuration.

That is why there are "Save Current" and "Save Main" options separately. I guess it could be "Save Default" instead for slightly less confusion. Or maybe not, since "default" implies the fresh default config instead of the default config path..

@RJNY
Copy link
Contributor Author

RJNY commented Feb 25, 2026

How does this work when RetroArch is started with a specific config file via the CLI parameter --config ? Does it save to the loaded file (which --config points to) or tries to save to the 'default' location ?

the snapshot is taken after args are parsed, so "Save Main" saves back to the argument specified file. I just tested this again on macOS to be sure.

"Save Main" is working on Windows as expected after loading any other than default, so if it does not do that with all platforms and this fixes it, then good.

thanks for testing on windows!

@sonninnos
Copy link
Collaborator

I meant it already works on Windows as-is, since the current method was developed on Windows. Would not make sense for the option to exist at all if it would not work anywhere: #18014

I have not tested this PR.

@RJNY
Copy link
Contributor Author

RJNY commented Feb 25, 2026

Got it.

To clarify, I was testing my changes on macOS to make sure I didn't break the existing --config behavior, not implying it was broken before. My changes don't touch that path, so it shouldn't be affected? just being cautious since I'm still getting familiar with the codebase and all its "potential pitfalls".

@LibretroAdmin LibretroAdmin merged commit 514258d into libretro:master Feb 25, 2026
35 checks passed
@LibretroAdmin
Copy link
Contributor

I merged it but if there are issues let me know here and we can return back to it

@cmitu
Copy link
Contributor

cmitu commented Feb 25, 2026

I did the same test (I think) as @sonninnos, but on Linux and - without this PR - I loaded a config file manually with 'Load Configuration'.

  • using 'Save current configuration' saves over the newly loaded file.
  • using 'Save main configuration' saves over the default ($HOME/.config/retroarch/retroarch.cfg, since retroarch was started without any --config parameter).

I'm not sure this PR is needed (on Linux and Windows is seems) ?

@RJNY
Copy link
Contributor Author

RJNY commented Feb 25, 2026

@cmitu can you test on Android? I think the issue is prominent for android users specifically.
I'll try to do the same later today after work, so no obligation if you're unable to.

edit: just for some context, I did prove the bug myself on android, and again in android development through adb installs. I'll want to confirm again after a full build.

Edit 2: I asked some that were affected by the issue to help confirm it was fixed. #16491

@cmitu
Copy link
Contributor

cmitu commented Feb 25, 2026

@cmitu can you test on Android? I think the issue is prominent for android users specifically.

I don't have a testing system with Android, sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants