diff --git a/command_event.c b/command_event.c index bb7a36d155..c0fa459c39 100644 --- a/command_event.c +++ b/command_event.c @@ -376,6 +376,12 @@ static void event_init_controllers(void) } } +static void event_deinit_core_interfaces(void) +{ + video_driver_callback_destroy_context(); + video_driver_unset_callback(); +} + static void event_deinit_core(bool reinit) { #ifdef HAVE_CHEEVOS @@ -383,14 +389,15 @@ static void event_deinit_core(bool reinit) cheevos_unload(); #endif + event_deinit_core_interfaces(); core.retro_unload_game(); core.retro_deinit(); if (reinit) event_command(EVENT_CMD_DRIVERS_DEINIT); - /* auto overrides: reload the original config */ - if(runloop_ctl(RUNLOOP_CTL_IS_OVERRIDES_ACTIVE, NULL)) + /* auto overrides: reload the original config */ + if (runloop_ctl(RUNLOOP_CTL_IS_OVERRIDES_ACTIVE, NULL)) { config_unload_override(); runloop_ctl(RUNLOOP_CTL_UNSET_OVERRIDES_ACTIVE, NULL); diff --git a/driver.c b/driver.c index b2acbfd908..bffeb194e1 100644 --- a/driver.c +++ b/driver.c @@ -405,15 +405,6 @@ static void uninit_drivers(int flags) if (flags & DRIVERS_VIDEO_INPUT) video_driver_ctl(RARCH_DISPLAY_CTL_DEINIT, NULL); - if (flags & DRIVER_VIDEO) - { - const struct retro_hw_render_callback *hw_render = - (const struct retro_hw_render_callback*)video_driver_callback(); - - if (hw_render->context_destroy && !video_driver_ctl(RARCH_DISPLAY_CTL_IS_VIDEO_CACHE_CONTEXT, NULL)) - hw_render->context_destroy(); - } - if ((flags & DRIVER_VIDEO) && !video_driver_ctl(RARCH_DISPLAY_CTL_OWNS_DRIVER, NULL)) video_driver_ctl(RARCH_DISPLAY_CTL_DESTROY_DATA, NULL); diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 58185f2ef9..9151313dc3 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -457,15 +457,6 @@ error: retro_fail(1, "init_video_input()"); } -static void video_driver_unset_callback(void) -{ - struct retro_hw_render_callback *hw_render = - video_driver_callback(); - - if (hw_render) - hw_render = NULL; -} - /** * video_monitor_compute_fps_statistics: * @@ -518,10 +509,24 @@ static void deinit_pixel_converter(void) video_driver_scaler_ptr = NULL; } +void video_driver_callback_destroy_context(void) +{ + const struct retro_hw_render_callback *hw_render = + (const struct retro_hw_render_callback*)video_driver_callback(); + if (hw_render->context_destroy) + hw_render->context_destroy(); +} + static bool uninit_video_input(void) { event_command(EVENT_CMD_OVERLAY_DEINIT); + if (!video_driver_ctl(RARCH_DISPLAY_CTL_IS_VIDEO_CACHE_CONTEXT, NULL)) + { + video_driver_callback_destroy_context(); + video_driver_unset_callback(); + } + if ( !input_driver_ctl(RARCH_INPUT_CTL_OWNS_DRIVER, NULL) && !input_driver_data_ptr_is_same(video_driver_data) @@ -539,7 +544,6 @@ static bool uninit_video_input(void) deinit_video_filter(); - video_driver_unset_callback(); event_command(EVENT_CMD_SHADER_DIR_DEINIT); video_monitor_compute_fps_statistics(); @@ -1080,6 +1084,12 @@ struct retro_hw_render_callback *video_driver_callback(void) return &video_driver_state.hw_render_callback; } +void video_driver_unset_callback(void) +{ + memset(&video_driver_state.hw_render_callback, 0, + sizeof(video_driver_state.hw_render_callback)); +} + static bool video_driver_frame_filter(const void *data, unsigned width, unsigned height, size_t pitch, diff --git a/gfx/video_driver.h b/gfx/video_driver.h index 1fe12a7e48..6b32daf936 100644 --- a/gfx/video_driver.h +++ b/gfx/video_driver.h @@ -425,6 +425,8 @@ float video_driver_get_aspect_ratio(void); void video_driver_set_aspect_ratio_value(float value); struct retro_hw_render_callback *video_driver_callback(void); +void video_driver_unset_callback(void); +void video_driver_callback_destroy_context(void); rarch_softfilter_t *video_driver_frame_filter_get_ptr(void);