diff --git a/frontend/menu/menu_common.c b/frontend/menu/menu_common.c index 3442e64601..e64f1a9234 100644 --- a/frontend/menu/menu_common.c +++ b/frontend/menu/menu_common.c @@ -33,7 +33,7 @@ #include "../../compat/posix_string.h" rgui_handle_t *rgui; -menu_ctx_driver_t *menu_ctx; +const menu_ctx_driver_t *menu_ctx; #ifdef HAVE_SHADER_MANAGER void shader_manager_init(rgui_handle_t *rgui) @@ -499,12 +499,7 @@ bool load_menu_game(void) void menu_init(void) { - menu_ctx = (menu_ctx_driver_t*)menu_ctx_init_first(); - - if (menu_ctx && menu_ctx->init) - rgui = (rgui_handle_t*)menu_ctx->init(); - - if (rgui == NULL || menu_ctx == NULL) + if (!menu_ctx_init_first(&menu_ctx, &rgui)) { RARCH_ERR("Could not initialize menu.\n"); rarch_fail(1, "menu_init()"); diff --git a/frontend/menu/menu_context.c b/frontend/menu/menu_context.c index 2ed28a616c..db3d287a14 100644 --- a/frontend/menu/menu_context.c +++ b/frontend/menu/menu_context.c @@ -44,10 +44,22 @@ const menu_ctx_driver_t *menu_ctx_find_driver(const char *ident) return NULL; } -const menu_ctx_driver_t *menu_ctx_init_first(void) +bool menu_ctx_init_first(const menu_ctx_driver_t **driver, rgui_handle_t **handle) { - for (unsigned i = 0; menu_ctx_drivers[i]; i++) - return menu_ctx_drivers[i]; + if (!menu_ctx_drivers[0]) + return false; - return NULL; + for (unsigned i = 0; menu_ctx_drivers[i]; i++) + { + void *h = menu_ctx_drivers[i]->init(); + if (h) + { + *driver = menu_ctx_drivers[i]; + *handle = h; + return true; + } + } + + return false; } + diff --git a/frontend/menu/menu_context.h b/frontend/menu/menu_context.h index c1c9ae1a68..1633ab502b 100644 --- a/frontend/menu/menu_context.h +++ b/frontend/menu/menu_context.h @@ -24,6 +24,8 @@ #include "../../config.h" #endif +#include "menu_common.h" + typedef struct menu_ctx_driver { int (*iterate)(void*); @@ -39,6 +41,6 @@ extern const menu_ctx_driver_t menu_ctx_rmenu_xui; extern const menu_ctx_driver_t menu_ctx_rgui; const menu_ctx_driver_t *menu_ctx_find_driver(const char *ident); // Finds driver with ident. Does not initialize. -const menu_ctx_driver_t *menu_ctx_init_first(void); // Finds first suitable driver and initializes. +bool menu_ctx_init_first(const menu_ctx_driver_t **driver, rgui_handle_t **handle); // Finds first suitable driver and initializes. #endif