input remapping: reset in-memory state on every content load (fix d4c8611 incomplete)

Commit d4c8611 ("Fix remapping default reset on close content")
added a defaults-reset to config_load_remap, but the new branch
fires only when sys_info->info.library_name is empty.  In the
reproducer reported against the original 9eb083a regression
(open content -> unbind ABXY in Quick Menu without saving a
remap file -> close content -> reopen same content), the core
is reinitialized and runloop_event_init_core() calls
retro_get_system_info() at runloop.c:4745 BEFORE the
config_load_remap() call at runloop.c:4828.  By the time
config_load_remap runs, sys_info->info.library_name is already
re-populated with the new core's name, so the new guard does
not fire, no tier file exists, and the function falls through
to 'return false' without ever resetting the per-port
input_remap_ids[][] arrays.  The unsaved unbinds from the
previous session persist into the new one.

Move the reset above the early-return guards so it fires on
every entry to config_load_remap, regardless of whether a
core name is set or a remap directory is configured.  This
is the load-path counterpart to input_remapping_cache_global_config()
in runloop_event_init_core: that function caches global
input settings on every content load so they can be restored
on unload; this reset clears the per-port remap arrays on
every content load so unsaved in-menu edits from a previous
session do not bleed through.

input_remapping_load_file() already calls
input_remapping_set_defaults(false) itself (configuration.c:6986)
before applying a tier file's bindings, so the double-reset
on the found-file path is harmless - it just clears arrays
that are about to be overwritten.  The menu remap-file
removal sites in menu_cbs_ok.c that 9eb083a was actually
targeting are unaffected, since this is the load path, not
the delete path.
This commit is contained in:
LibretroAdmin authored and U-DESKTOP-SPFP6AQ\twistedtechre committed 2026-05-14 21:15:37 +02:00
1 parent 3cbdaa2a7b
commit 67ade86dc5
1 file changed
+18 -8
+18 -8
View File
@@ -5046,15 +5046,25 @@ bool config_load_remap(const char *directory_input_remapping,
bool notification_show_remap_load = settings->bools.notification_show_remap_load;
bool sort_remaps_by_controller = settings->bools.input_remap_sort_by_controller_enable;
/* Reset defaults if we have no core */
if (!core_name || !*core_name)
{
input_remapping_set_defaults(false);
return false;
}
/* Always reset the in-memory remap state on entry. This is the
* load-path counterpart to input_remapping_cache_global_config()
* in runloop.c: when a content load reaches this point, any
* unsaved per-port edits from a previous session must be
* cleared before either a tier file is loaded or we fall
* through with no file (otherwise stale edits persist into
* the new session, since the unload-paths in runloop /
* retroarch only call set_defaults when a remap file or
* REMAPS_*_ACTIVE flag was in effect).
*
* If a tier file is found below, input_remapping_load_file()
* calls input_remapping_set_defaults() itself before applying
* the file's bindings, so this reset is harmless on the
* found-file path. */
input_remapping_set_defaults(false);
/* Cannot load remaps if remap directory is unset */
if (!directory_input_remapping || !*directory_input_remapping)
/* Cannot load remaps if we have no core or no remap directory */
if ( (!core_name || !*core_name)
|| (!directory_input_remapping || !*directory_input_remapping))
return false;
core_path[0] = '\0';