From 456075a2cb922894ed78a48ec32bc86587ae0474 Mon Sep 17 00:00:00 2001 From: matcool <26722564+matcool@users.noreply.github.com> Date: Mon, 12 Feb 2024 15:55:13 -0300 Subject: [PATCH] (urgent) fix log mutex breaking forward compat mode yes, this single mutex would break geode loading in forward compat mode entirely.. because the forward compat hooks log at static init time! and since static init stuff is weird, the mutex wasnt initialized yet. so now we force it to be initialized by having it in a getter --- loader/src/loader/Log.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/loader/src/loader/Log.cpp b/loader/src/loader/Log.cpp index 9880bb04..66d2d6f7 100644 --- a/loader/src/loader/Log.cpp +++ b/loader/src/loader/Log.cpp @@ -215,18 +215,22 @@ void Logger::setup() { m_logStream = std::ofstream(dirs::getGeodeLogDir() / log::generateLogName()); } -std::mutex g_logMutex; +std::mutex& getLogMutex() { + static std::mutex mutex; + return mutex; +} + void Logger::push(Severity sev, std::string&& thread, std::string&& source, int32_t nestCount, std::string&& content) { Log* log; { - std::lock_guard g(g_logMutex); + std::lock_guard g(getLogMutex()); log = &m_logs.emplace_back(sev, std::move(thread), std::move(source), nestCount, std::move(content)); } auto const logStr = log->toString(); { - std::lock_guard g(g_logMutex); + std::lock_guard g(getLogMutex()); console::log(logStr, log->getSeverity()); m_logStream << logStr << std::endl; } @@ -241,7 +245,7 @@ std::vector const& Logger::list() { } void Logger::clear() { - std::lock_guard g(g_logMutex); + std::lock_guard g(getLogMutex()); m_logs.clear(); }