From d98cd5a680502afa31300c8bf04849de0face89b Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 10 Feb 2015 16:46:49 +0100 Subject: [PATCH 1/3] runloop.c - create check_video_alive - try to prevent segfaults at all costs --- runloop.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/runloop.c b/runloop.c index 45fcc038a9..0fbb4fd8ed 100644 --- a/runloop.c +++ b/runloop.c @@ -612,6 +612,15 @@ static int do_state_checks( return 0; } +static inline bool check_video_alive(void) +{ + if (!driver.video || !driver.video_data) + return false; + if (!driver.video->alive(driver.video_data)) + return false; + return true; +} + /** * time_to_exit: * @input : input sample for this frame @@ -636,7 +645,7 @@ static inline int time_to_exit(retro_input_t input) || (g_extern.max_frames && g_extern.frame_count >= g_extern.max_frames) || (g_extern.bsv.movie_end && g_extern.bsv.eof_exit) - || !driver.video->alive(driver.video_data) + || check_video_alive() ) return 1; return 0; From 5921f8055d0116386f70639ebb7c07a1d5495ed9 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 10 Feb 2015 16:50:41 +0100 Subject: [PATCH 2/3] Refactor this --- runloop.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/runloop.c b/runloop.c index 0fbb4fd8ed..68c046d863 100644 --- a/runloop.c +++ b/runloop.c @@ -612,15 +612,6 @@ static int do_state_checks( return 0; } -static inline bool check_video_alive(void) -{ - if (!driver.video || !driver.video_data) - return false; - if (!driver.video->alive(driver.video_data)) - return false; - return true; -} - /** * time_to_exit: * @input : input sample for this frame @@ -639,13 +630,15 @@ static inline bool check_video_alive(void) **/ static inline int time_to_exit(retro_input_t input) { + if (!driver.video || !driver.video_data) + return 0; if ( g_extern.system.shutdown || check_quit_key_func(input) || (g_extern.max_frames && g_extern.frame_count >= g_extern.max_frames) || (g_extern.bsv.movie_end && g_extern.bsv.eof_exit) - || check_video_alive() + || !driver.video->alive(driver.video_data) ) return 1; return 0; From 81ca20c9b5d5fdd0adfe4a3f6f3b497f15c74695 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 10 Feb 2015 16:54:08 +0100 Subject: [PATCH 3/3] Create wrapper function for 'is video alive' --- gfx/video_driver.c | 10 ++++++++++ gfx/video_driver.h | 2 ++ runloop.c | 4 +--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 7e52513e76..c1fe7845d5 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -233,6 +233,16 @@ void video_driver_make_current_context(void) driver.video_poke->make_current_context(driver.video_data); } +bool video_driver_is_alive(void) +{ + /* Possible race issue, return true */ + if (!driver.video || !driver.video_data) + return true; + if (!driver.video->alive(driver.video_data)) + return false; + return true; +} + static void deinit_video_filter(void) { rarch_softfilter_free(g_extern.filter.filter); diff --git a/gfx/video_driver.h b/gfx/video_driver.h index d4cd285588..acafb73024 100644 --- a/gfx/video_driver.h +++ b/gfx/video_driver.h @@ -244,6 +244,8 @@ retro_proc_address_t video_driver_get_proc_address(const char *sym); void video_driver_make_current_context(void); +bool video_driver_is_alive(void); + void uninit_video_input(void); void init_video(void); diff --git a/runloop.c b/runloop.c index 68c046d863..5247e4d262 100644 --- a/runloop.c +++ b/runloop.c @@ -630,15 +630,13 @@ static int do_state_checks( **/ static inline int time_to_exit(retro_input_t input) { - if (!driver.video || !driver.video_data) - return 0; if ( g_extern.system.shutdown || check_quit_key_func(input) || (g_extern.max_frames && g_extern.frame_count >= g_extern.max_frames) || (g_extern.bsv.movie_end && g_extern.bsv.eof_exit) - || !driver.video->alive(driver.video_data) + || !video_driver_is_alive() ) return 1; return 0;