From 8935d9db1b3459c561d14654d65f82a77b3c66f6 Mon Sep 17 00:00:00 2001 From: Jonathan Rascher Date: Wed, 26 Jun 2024 22:17:21 -0500 Subject: [PATCH] Skip core unload when Quit on Close Content is set --- menu/cbs/menu_cbs_ok.c | 5 +++-- retroarch.c | 13 +++++++++---- retroarch.h | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index 13842163f4..0fede1508a 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -5598,9 +5598,10 @@ int action_ok_close_content(const char *path, const char *label, unsigned type, menu_st->selection_ptr = 0; /* Check if we need to quit */ - check_quit_on_close(); + if (should_quit_on_close()) + return generic_action_ok_command(CMD_EVENT_QUIT); - /* Unload core */ + /* Otherwise, unload core */ ret = generic_action_ok_command(CMD_EVENT_UNLOAD_CORE); /* If close content was selected via any means other than diff --git a/retroarch.c b/retroarch.c index f3dec5dd32..06821a8bc6 100644 --- a/retroarch.c +++ b/retroarch.c @@ -3723,6 +3723,12 @@ bool command_event(enum event_command cmd, void *data) break; case CMD_EVENT_CLOSE_CONTENT: #ifdef HAVE_MENU + /* If we need to quit, skip unloading the core to avoid performing + * cleanup actions (like writing autosave state) twice. */ + if (should_quit_on_close()) { + command_event(CMD_EVENT_QUIT, NULL); + break; + } /* Closing content via hotkey requires toggling menu * and resetting the position later on to prevent * going to empty Quick Menu */ @@ -3731,8 +3737,6 @@ bool command_event(enum event_command cmd, void *data) menu_state_get_ptr()->flags |= MENU_ST_FLAG_PENDING_CLOSE_CONTENT; command_event(CMD_EVENT_MENU_TOGGLE, NULL); } - /* Check if we need to quit Retroarch */ - check_quit_on_close(); #else command_event(CMD_EVENT_QUIT, NULL); #endif @@ -8212,7 +8216,7 @@ void retroarch_fail(int error_code, const char *error) } /* Called on close content, checks if we need to also exit retroarch */ -void check_quit_on_close(void) +bool should_quit_on_close(void) { #ifdef HAVE_MENU settings_t *settings = config_get_ptr(); @@ -8223,8 +8227,9 @@ void check_quit_on_close(void) || (settings->uints.quit_on_close_content == QUIT_ON_CLOSE_CONTENT_ENABLED) ) - command_event(CMD_EVENT_QUIT, NULL); + return true; #endif + return false; } /* diff --git a/retroarch.h b/retroarch.h index 7da4e39482..2d1900766c 100644 --- a/retroarch.h +++ b/retroarch.h @@ -206,7 +206,7 @@ void core_options_flush(void); **/ void retroarch_fail(int error_code, const char *error); -void check_quit_on_close(void); +bool should_quit_on_close(void); uint16_t retroarch_get_flags(void);