From 62be540702db180b518722e5ffa23ffbf6356dee Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sat, 18 Mar 2023 14:10:29 +0100 Subject: [PATCH] Properly shutdown SpdLog Shutdown SpdLog on SDK shutdown or crash, this makes sure the buffers gets flushed. --- r5dev/core/dllmain.cpp | 3 ++- r5dev/core/logdef.cpp | 15 +++++++++++++-- r5dev/core/logdef.h | 1 + r5dev/tier0/crashhandler.cpp | 7 ++++++- r5dev/windows/console.cpp | 14 ++++++++++++++ r5dev/windows/console.h | 2 ++ 6 files changed, 38 insertions(+), 4 deletions(-) diff --git a/r5dev/core/dllmain.cpp b/r5dev/core/dllmain.cpp index 464137cb..6235b58a 100644 --- a/r5dev/core/dllmain.cpp +++ b/r5dev/core/dllmain.cpp @@ -85,7 +85,8 @@ void SDK_Shutdown() DirectX_Shutdown(); #endif // !DEDICATED - FreeConsole(); + Console_Shutdown(); + SpdLog_Shutdown(); } //############################################################################# diff --git a/r5dev/core/logdef.cpp b/r5dev/core/logdef.cpp index 6ed8ecd7..c5bc7caa 100644 --- a/r5dev/core/logdef.cpp +++ b/r5dev/core/logdef.cpp @@ -2,7 +2,7 @@ #include "core/logdef.h" //############################################################################# -// SPDLOG SETUP +// SPDLOG INIT //############################################################################# void SpdLog_Init(void) { @@ -65,6 +65,9 @@ void SpdLog_Init(void) bInitialized = true; } +//############################################################################# +// SPDLOG POST INIT +//############################################################################# void SpdLog_PostInit() { std::shared_ptr iconsole = spdlog::get("game_console"); @@ -79,4 +82,12 @@ void SpdLog_PostInit() } else { wconsole->set_pattern("%v"); } g_bSpdLog_PostInit = true; -} \ No newline at end of file +} + +//############################################################################# +// SPDLOG SHUTDOWN +//############################################################################# +void SpdLog_Shutdown() +{ + spdlog::shutdown(); +} diff --git a/r5dev/core/logdef.h b/r5dev/core/logdef.h index 7a40ba61..834ecfe2 100644 --- a/r5dev/core/logdef.h +++ b/r5dev/core/logdef.h @@ -15,3 +15,4 @@ inline auto g_spd_sys_p_ostream_sink = std::make_sharedGetState()) + { + // Shutdown SpdLog to flush all buffers. + SpdLog_Shutdown(); ExitProcess(1u); + } + g_CrashHandler->SetState(true); g_CrashHandler->FormatCrash(); @@ -624,4 +629,4 @@ CCrashHandler::~CCrashHandler() Shutdown(); } -CCrashHandler* g_CrashHandler = new CCrashHandler(); \ No newline at end of file +CCrashHandler* g_CrashHandler = new CCrashHandler(); diff --git a/r5dev/windows/console.cpp b/r5dev/windows/console.cpp index 5cf2e2b9..b52048ce 100644 --- a/r5dev/windows/console.cpp +++ b/r5dev/windows/console.cpp @@ -120,6 +120,20 @@ void Console_Init() SetConsoleCtrlHandler(ConsoleHandlerRoutine, true); } +//----------------------------------------------------------------------------- +// Purpose: terminal window shutdown +//----------------------------------------------------------------------------- +void Console_Shutdown() +{ + /////////////////////////////////////////////////////////////////////////// + // Destroy the console window + if (FreeConsole() == FALSE) + { + OutputDebugStringA("Failed to destroy console window!\n"); + return; + } +} + //############################################################################# // WORKER THREAD //############################################################################# diff --git a/r5dev/windows/console.h b/r5dev/windows/console.h index e42d960d..3e6b4d1f 100644 --- a/r5dev/windows/console.h +++ b/r5dev/windows/console.h @@ -2,4 +2,6 @@ void SetConsoleBackgroundColor(COLORREF color); void FlashConsoleBackground(int nFlashCount, int nFlashInterval, COLORREF color); + void Console_Init(); +void Console_Shutdown();