From 638a015cedd7d9a5db2b83117de334fc5cd706db Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 15 Apr 2017 16:30:37 -0700 Subject: [PATCH] Add a restarting flag to NativeInit/NativeShutdown. Will be used externally. Also cleanup some LogManager init/shutdown in case these are called multiple times on Windows. --- Core/Config.cpp | 3 ++- UI/NativeApp.cpp | 21 +++++++++++++++++++-- ext/native/base/NativeApp.h | 6 ++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index e6e41ff119..76bbd45f7a 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -1094,7 +1094,8 @@ void Config::Save() { control->Delete("DPadRadius"); IniFile::Section *log = iniFile.GetOrCreateSection(logSectionName); - LogManager::GetInstance()->SaveConfig(log); + if (LogManager::GetInstance()) + LogManager::GetInstance()->SaveConfig(log); if (!iniFile.Save(iniFilename_.c_str())) { ERROR_LOG(LOADER, "Error saving config - can't write ini %s", iniFilename_.c_str()); diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index e6eeb13397..89b86fa24a 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -134,6 +134,7 @@ bool targetIsJailbroken; bool g_TakeScreenshot; static bool isOuya; static bool resized = false; +static bool restarting = false; struct PendingMessage { std::string msg; @@ -361,8 +362,10 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch g_Config.appCacheDirectory = cache_dir; } + if (!LogManager::GetInstance()) + LogManager::Init(); + #ifndef _WIN32 - LogManager::Init(); logger = new AndroidLogger(); g_Config.AddSearchPath(user_data_path); @@ -532,6 +535,9 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch if (GetGPUBackend() == GPUBackend::OPENGL) { gl_lost_manager_init(); } + + // Must be done restarting by now. + restarting = false; } static UI::Style MakeStyle(uint32_t fg, uint32_t bg) { @@ -1051,6 +1057,14 @@ void NativeResized() { resized = true; } +void NativeSetRestarting() { + restarting = true; +} + +bool NativeIsRestarting() { + return restarting; +} + void NativeShutdown() { if (GetGPUBackend() == GPUBackend::OPENGL) { gl_lost_manager_shutdown(); @@ -1065,7 +1079,10 @@ void NativeShutdown() { #endif host = 0; g_Config.Save(); - LogManager::Shutdown(); + + // Avoid shutting this down when restaring core. + if (!restarting) + LogManager::Shutdown(); #ifdef ANDROID_NDK_PROFILER moncleanup(); diff --git a/ext/native/base/NativeApp.h b/ext/native/base/NativeApp.h index e598e31677..3cea3a4c8d 100644 --- a/ext/native/base/NativeApp.h +++ b/ext/native/base/NativeApp.h @@ -63,6 +63,12 @@ void NativeDeviceRestore(); // and only write dp_xres and dp_yres. void NativeResized(); +// Set a flag to indicate a restart. Reset after NativeInit(). +void NativeSetRestarting(); + +// Retrieve current restarting flag. +bool NativeIsRestarting(); + // Called ~sixty times a second, delivers the current input state. // Main thread. void NativeUpdate();