From a67de5bc5825fa1f527f252670d091fb1deea3a8 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sat, 18 Mar 2023 21:42:30 +0100 Subject: [PATCH] Fix init crash on builds compiled with MSVC14 The MSVC14 (Visual Studio 2017) compiler doesn't support creating threads during dll entry. SDK fixed frame thread init has been moved to 'CModAppSystemGroup::Main'. SpdLog buffer flush worker init has been moved to 'SpdLog_PostInit', and 'SpdLog_PostInit' has been moved to 'LauncherMain'. --- r5dev/core/init.cpp | 4 ---- r5dev/core/logdef.cpp | 4 ++-- r5dev/launcher/IApplication.cpp | 4 ++++ r5dev/launcher/launcher.cpp | 3 +++ 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/r5dev/core/init.cpp b/r5dev/core/init.cpp index 3388e085..815dd463 100644 --- a/r5dev/core/init.cpp +++ b/r5dev/core/init.cpp @@ -184,10 +184,6 @@ void Systems_Init() spdlog::info("+-------------------------------------------------------------+\n"); ConVar::Init(); - SpdLog_PostInit(); - - std::thread fixed(&CEngineSDK::FixedFrame, g_EngineSDK); - fixed.detach(); } ////////////////////////////////////////////////////////////////////////// diff --git a/r5dev/core/logdef.cpp b/r5dev/core/logdef.cpp index c5bc7caa..6c105ce5 100644 --- a/r5dev/core/logdef.cpp +++ b/r5dev/core/logdef.cpp @@ -60,8 +60,6 @@ void SpdLog_Init(void) } spdlog::set_level(spdlog::level::trace); - spdlog::flush_every(std::chrono::seconds(5)); // Flush buffers every 5 seconds for every logger. - bInitialized = true; } @@ -70,6 +68,8 @@ void SpdLog_Init(void) //############################################################################# void SpdLog_PostInit() { + spdlog::flush_every(std::chrono::seconds(5)); // Flush buffers every 5 seconds for every logger. + std::shared_ptr iconsole = spdlog::get("game_console"); std::shared_ptr wconsole = spdlog::get("win_console"); diff --git a/r5dev/launcher/IApplication.cpp b/r5dev/launcher/IApplication.cpp index 86efb8f1..e12c35cd 100644 --- a/r5dev/launcher/IApplication.cpp +++ b/r5dev/launcher/IApplication.cpp @@ -16,6 +16,7 @@ #include "engine/cmodel_bsp.h" #include "engine/sys_engine.h" #include "engine/sys_dll2.h" +#include "engine/sdk_dll.h" #include "engine/host_cmd.h" #include "engine/enginetrace.h" #include "engine/server/sv_main.h" @@ -37,6 +38,9 @@ //----------------------------------------------------------------------------- int CModAppSystemGroup::Main(CModAppSystemGroup* pModAppSystemGroup) { + std::thread fixed(&CEngineSDK::FixedFrame, g_EngineSDK); + fixed.detach(); + int nRunResult = RUN_OK; HEbisuSDK_Init(); // Not here in retail. We init EbisuSDK here though. diff --git a/r5dev/launcher/launcher.cpp b/r5dev/launcher/launcher.cpp index 6f816d24..547a0460 100644 --- a/r5dev/launcher/launcher.cpp +++ b/r5dev/launcher/launcher.cpp @@ -5,6 +5,7 @@ // $NoKeywords: $ //===========================================================================// #include "core/stdafx.h" +#include "core/logdef.h" #include "tier0/crashhandler.h" #include "tier0/commandline.h" #include "tier1/strtools.h" @@ -30,6 +31,8 @@ int HWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int int LauncherMain(HINSTANCE hInstance) { + SpdLog_PostInit(); + int results = v_LauncherMain(hInstance); spdlog::info("LauncherMain returned: {:s}\n", ExitCodeToString(results)); return results;