Skip to content

Commit

Permalink
Fix quit on content close option (#16014)
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
davidgfnet authored Dec 21, 2023
1 parent 93f7bba commit 3194dc9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
2 changes: 2 additions & 0 deletions menu/cbs/menu_cbs_ok.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
27 changes: 18 additions & 9 deletions retroarch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions retroarch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3194dc9

Please sign in to comment.