From 74ae6ecf576f2c88c2bc8e4378ac3ee942258385 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 17 Dec 2012 18:45:26 +0100 Subject: [PATCH] (Android) Better deinit - will now deinit RetroArch and save game RAM if you forcibly stop RetroArch --- android/native/jni/android_glue.h | 1 - android/native/jni/input_android.c | 4 +--- android/native/jni/main.c | 13 ++++--------- driver.h | 1 - gfx/context/androidegl_ctx.c | 2 +- 5 files changed, 6 insertions(+), 15 deletions(-) diff --git a/android/native/jni/android_glue.h b/android/native/jni/android_glue.h index d90d8ac22c..0c4b5c9608 100644 --- a/android/native/jni/android_glue.h +++ b/android/native/jni/android_glue.h @@ -49,7 +49,6 @@ struct android_app ANativeWindow* window; ARect contentRect; int activityState; - int destroyRequested; pthread_mutex_t mutex; pthread_cond_t cond; diff --git a/android/native/jni/input_android.c b/android/native/jni/input_android.c index 28e7f1685f..9fad8a5919 100644 --- a/android/native/jni/input_android.c +++ b/android/native/jni/input_android.c @@ -371,9 +371,7 @@ static bool android_input_key_pressed(void *data, int key) { (void)data; - if(key == RARCH_QUIT_KEY && (g_extern.lifecycle_state & (1ULL << RARCH_KILL))) - return true; - else if(g_extern.lifecycle_state & (1ULL << key)) + if(g_extern.lifecycle_state & (1ULL << key)) return true; return false; diff --git a/android/native/jni/main.c b/android/native/jni/main.c index a98093e128..9d4025f2e6 100644 --- a/android/native/jni/main.c +++ b/android/native/jni/main.c @@ -245,7 +245,7 @@ void engine_handle_cmd(struct android_app* android_app, int32_t cmd) RARCH_LOG("engine_handle_cmd: APP_CMD_DESTROY\n"); /* PREEXEC */ - android_app->destroyRequested = 1; + g_extern.lifecycle_state |= (1ULL << RARCH_QUIT_KEY); break; } } @@ -288,7 +288,7 @@ bool android_run_events(struct android_app* android_app) } // Check if we are exiting. - if (android_app->destroyRequested != 0) + if (g_extern.lifecycle_state & (1ULL << RARCH_QUIT_KEY)) return false; } @@ -435,7 +435,6 @@ static void* android_app_entry(void* param) { RARCH_LOG("Initialization failed.\n"); g_extern.lifecycle_state |= (1ULL << RARCH_QUIT_KEY); - g_extern.lifecycle_state |= (1ULL << RARCH_KILL); } else RARCH_LOG("Initializing succeeded.\n"); @@ -460,12 +459,7 @@ exit: #endif rarch_main_clear_state(); - /* Make sure to quit RetroArch later on too */ - g_extern.lifecycle_state |= (1ULL << RARCH_KILL); - } - - if(g_extern.lifecycle_state & (1ULL << RARCH_KILL)) - { + /* Quit RetroArch */ RARCH_LOG("android_app_destroy!"); free_saved_state(android_app); pthread_mutex_lock(&android_app->mutex); @@ -480,6 +474,7 @@ exit: // Can't touch android_app object after this. exit(0); } + return NULL; } diff --git a/driver.h b/driver.h index aa8a2286c4..1b87d5554e 100644 --- a/driver.h +++ b/driver.h @@ -104,7 +104,6 @@ enum // RetroArch specific bind IDs. RARCH_SRAM_WRITE_PROTECT, #endif #ifdef ANDROID - RARCH_KILL, RARCH_WINDOW_READY, #endif #ifdef HAVE_RMENU diff --git a/gfx/context/androidegl_ctx.c b/gfx/context/androidegl_ctx.c index 3867f959e3..4e8e5be21b 100644 --- a/gfx/context/androidegl_ctx.c +++ b/gfx/context/androidegl_ctx.c @@ -251,7 +251,7 @@ static void gfx_ctx_check_window(bool *quit, } // Check if we are exiting. - if (g_android.app->destroyRequested != 0 || (g_extern.lifecycle_state & (1ULL << RARCH_KILL))) + if (g_extern.lifecycle_state & (1ULL << RARCH_QUIT_KEY)) *quit = true; }