diff --git a/Common/ConsoleListener.cpp b/Common/ConsoleListener.cpp index 16bbfc5f99..7f9e0a7f71 100644 --- a/Common/ConsoleListener.cpp +++ b/Common/ConsoleListener.cpp @@ -181,8 +181,6 @@ void ConsoleListener::UpdateHandle() void ConsoleListener::Close() { #if defined(USING_WIN_UI) - if (hConsole == NULL) - return; if (--refCount <= 0) { @@ -209,8 +207,10 @@ void ConsoleListener::Close() refCount = 0; } - FreeConsole(); - hConsole = NULL; + if (hConsole != NULL) { + FreeConsole(); + hConsole = NULL; + } #else fflush(NULL); #endif diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index bc7d143d8e..423b6ec204 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -331,7 +331,9 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch VFSRegister("", new DirectoryAssetReader(savegame_dir)); #if (defined(MOBILE_DEVICE) || !defined(USING_QT_UI)) && !PPSSPP_PLATFORM(UWP) - host = new NativeHost(); + if (host == nullptr) { + host = new NativeHost(); + } #endif #if defined(__ANDROID__) @@ -526,7 +528,9 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch #if !defined(MOBILE_DEVICE) && defined(USING_QT_UI) MainWindow* mainWindow = new MainWindow(0,fs); mainWindow->show(); - host = new QtHost(mainWindow); + if (host == nullptr) { + host = new QtHost(mainWindow); + } #endif // We do this here, instead of in NativeInitGraphics, because the display may be reset. @@ -1066,18 +1070,19 @@ bool NativeIsRestarting() { } void NativeShutdown() { + screenManager->shutdown(); + delete screenManager; + screenManager = nullptr; + + host->ShutdownGraphics(); if (GetGPUBackend() == GPUBackend::OPENGL) { gl_lost_manager_shutdown(); } - screenManager->shutdown(); - delete screenManager; - screenManager = 0; - #if !PPSSPP_PLATFORM(UWP) delete host; + host = nullptr; #endif - host = 0; g_Config.Save(); // Avoid shutting this down when restaring core. diff --git a/Windows/EmuThread.cpp b/Windows/EmuThread.cpp index 5bdec61383..b576196892 100644 --- a/Windows/EmuThread.cpp +++ b/Windows/EmuThread.cpp @@ -77,7 +77,7 @@ void EmuThread_Stop() CloseHandle(emuThread); emuThread = 0; } - host->UpdateUI(); + PostMessage(MainWindow::GetHWND(), MainWindow::WM_USER_UPDATE_UI, 0, 0); } bool EmuThread_Ready() @@ -91,10 +91,6 @@ unsigned int WINAPI TheThread(void *) setCurrentThreadName("Emu"); // And graphics... - // Native overwrites host. Can't allow that. - - Host *oldHost = host; - // Convert the command-line arguments to Unicode, then to proper UTF-8 // (the benefit being that we don't have to pollute the UI project with win32 ifdefs and lots of ConvertTo). // This avoids issues with PPSSPP inadvertently destroying paths with Unicode glyphs @@ -115,9 +111,6 @@ unsigned int WINAPI TheThread(void *) bool performingRestart = NativeIsRestarting(); NativeInit(static_cast(args.size()), &args[0], "1234", "1234", nullptr); - Host *nativeHost = host; - host = oldHost; - host->UpdateUI(); GraphicsContext *graphicsContext; @@ -204,12 +197,7 @@ shutdown: _InterlockedExchange(&emuThreadReady, THREAD_SHUTDOWN); NativeShutdownGraphics(); - - host->ShutdownSound(); - host = nativeHost; NativeShutdown(); - host = oldHost; - host->ShutdownGraphics(); _InterlockedExchange(&emuThreadReady, THREAD_END); diff --git a/headless/Headless.cpp b/headless/Headless.cpp index 748c67cf81..53a29ef666 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -200,6 +200,10 @@ int main(int argc, const char* argv[]) { PROFILE_INIT(); +#ifdef _DEBUG + _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); +#endif + #ifdef ANDROID_NDK_PROFILER setenv("CPUPROFILE_FREQUENCY", "500", 1); setenv("CPUPROFILE", "/sdcard/gmon.out", 1); @@ -433,8 +437,12 @@ int main(int argc, const char* argv[]) host->ShutdownGraphics(); delete host; - host = NULL; - headlessHost = NULL; + host = nullptr; + headlessHost = nullptr; + + VFSShutdown(); + LogManager::Shutdown(); + delete printfLogger; #ifdef ANDROID_NDK_PROFILER moncleanup();