From fe08806aa52b194d9cdfedeb7549c686f62e4b26 Mon Sep 17 00:00:00 2001 From: meancoot Date: Tue, 13 Aug 2013 22:42:56 -0400 Subject: [PATCH] (iOS) Use the nuclear option for life-cycle management. This should fix hangs caused by incoming calls or launching siri, but will cause more driver reinits than before --- apple/RetroArch/RAGameView.m | 20 +------------------- apple/RetroArch/RetroArch_Apple.h | 3 --- apple/RetroArch/main.m | 25 +++++++++++++++++++++---- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/apple/RetroArch/RAGameView.m b/apple/RetroArch/RAGameView.m index a9b8f174a4..daa9fd97e9 100644 --- a/apple/RetroArch/RAGameView.m +++ b/apple/RetroArch/RAGameView.m @@ -189,17 +189,6 @@ static float g_screen_scale = 1.0f; ]; } -- (void)suspend -{ - g_view.context = nil; - [EAGLContext setCurrentContext:nil]; -} - -- (void)resume -{ - g_view.context = g_context; - [EAGLContext setCurrentContext:g_context]; -} #endif @end @@ -215,7 +204,7 @@ bool apple_init_game_view() g_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; [EAGLContext setCurrentContext:g_context]; g_view.context = g_context; - + // Show pause button for a few seconds, so people know it's there g_pause_indicator_view.alpha = 1.0f; [NSObject cancelPreviousPerformRequestsWithTarget:g_instance]; @@ -232,13 +221,6 @@ bool apple_init_game_view() void apple_destroy_game_view() { dispatch_sync(dispatch_get_main_queue(), ^{ - // Clear the view, otherwise the last frame from this game will be displayed - // briefly on the next game. - [g_view bindDrawable]; - glClearColor(0, 0, 0, 1); - glClear(GL_COLOR_BUFFER_BIT); - [g_view display]; - glFinish(); #ifdef IOS diff --git a/apple/RetroArch/RetroArch_Apple.h b/apple/RetroArch/RetroArch_Apple.h index 5302d3a4c2..39096304d5 100644 --- a/apple/RetroArch/RetroArch_Apple.h +++ b/apple/RetroArch/RetroArch_Apple.h @@ -39,9 +39,6 @@ extern id apple_platform; + (RAGameView*)get; - (void)openPauseMenu; - (void)closePauseMenu; - -- (void)suspend; -- (void)resume; @end @interface RetroArch_iOS : UINavigationController diff --git a/apple/RetroArch/main.m b/apple/RetroArch/main.m index b14f7190f2..12e0361392 100644 --- a/apple/RetroArch/main.m +++ b/apple/RetroArch/main.m @@ -83,6 +83,18 @@ static void event_reload_config(void* userdata) init_drivers(); } +static pthread_mutex_t stasis_mutex = PTHREAD_MUTEX_INITIALIZER; + +static void event_stasis(void* userdata) +{ + // HACK: uninit_drivers is the nuclear option; uninit_audio would be better but will + // crash when resuming. + uninit_drivers(); + pthread_mutex_lock(&stasis_mutex); + pthread_mutex_unlock(&stasis_mutex); + init_drivers(); +} + #pragma mark EMULATION static pthread_t apple_retro_thread; static bool apple_is_paused; @@ -258,14 +270,19 @@ int main(int argc, char *argv[]) apple_display_alert(@"No libretro cores were found. You will not be able to play any games.", 0); } -- (void)applicationWillEnterForeground:(UIApplication *)application +- (void)applicationDidBecomeActive:(UIApplication *)application { - [RAGameView.get resume]; + if (apple_is_running) + pthread_mutex_unlock(&stasis_mutex); } -- (void)applicationDidEnterBackground:(UIApplication *)application +- (void)applicationWillResignActive:(UIApplication *)application { - [RAGameView.get suspend]; + if (apple_is_running) + { + pthread_mutex_lock(&stasis_mutex); + apple_frontend_post_event(event_stasis, 0); + } } // UINavigationControllerDelegate