From 3194dc9d653dce182f6aa8d71e74ecbadb0e190f Mon Sep 17 00:00:00 2001 From: "David G. F" Date: Thu, 21 Dec 2023 01:23:18 +0100 Subject: [PATCH] Fix quit on content close option (#16014) Right now close is based on core unload. There are several places where cores are unloaded without the intention of stopping the emulation (for instance whenever Netplay is started, core is updated, etc). Moreover scheduling a quit under some of those events causes a task queue deadlock (as per issue #15313) and freezed retroarch. This fix moves the quit on close to a "manual" check, placed in the relevant places (close content menu option, close content event (which also covers hotkeys), etc.) --- menu/cbs/menu_cbs_ok.c | 2 ++ retroarch.c | 27 ++++++++++++++++++--------- retroarch.h | 2 ++ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index 21dbcf2e2f..9c86d92c8a 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -5572,6 +5572,8 @@ int action_ok_close_content(const char *path, const char *label, unsigned type, menu_st->flags &= ~MENU_ST_FLAG_PREVENT_POPULATE; } + check_quit_on_close(); + return ret; } diff --git a/retroarch.c b/retroarch.c index d8f0f54965..cd5b4fe7a2 100644 --- a/retroarch.c +++ b/retroarch.c @@ -3645,15 +3645,6 @@ bool command_event(enum event_command cmd, void *data) if ( (flags & CONTENT_ST_FLAG_IS_INITED) && load_dummy_core) { -#ifdef HAVE_MENU - if ( ((settings->uints.quit_on_close_content == - QUIT_ON_CLOSE_CONTENT_CLI) - && global->launched_from_cli) - || (settings->uints.quit_on_close_content == - QUIT_ON_CLOSE_CONTENT_ENABLED) - ) - command_event(CMD_EVENT_QUIT, NULL); -#endif if (!task_push_start_dummy_core(&content_info)) return false; } @@ -3693,6 +3684,8 @@ 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 @@ -8020,6 +8013,22 @@ void retroarch_fail(int error_code, const char *error) longjmp(global->error_sjlj_context, error_code); } +/* Called on close content, checks if we need to also exit retroarch */ +void check_quit_on_close(void) +{ +#ifdef HAVE_MENU + settings_t *settings = config_get_ptr(); + global_t *global = global_get_ptr(); + if ( ((settings->uints.quit_on_close_content == + QUIT_ON_CLOSE_CONTENT_CLI) + && global->launched_from_cli) + || (settings->uints.quit_on_close_content == + QUIT_ON_CLOSE_CONTENT_ENABLED) + ) + command_event(CMD_EVENT_QUIT, NULL); +#endif +} + /* * Also saves configuration files to disk, * and (optionally) autosave state. diff --git a/retroarch.h b/retroarch.h index f806a85831..7da4e39482 100644 --- a/retroarch.h +++ b/retroarch.h @@ -206,6 +206,8 @@ void core_options_flush(void); **/ void retroarch_fail(int error_code, const char *error); +void check_quit_on_close(void); + uint16_t retroarch_get_flags(void); RETRO_END_DECLS