From cffee2b7f83b99201a18653803c196a0737cc864 Mon Sep 17 00:00:00 2001 From: bicarus-dev <202771338+bicarus-dev@users.noreply.github.com> Date: Thu, 2 Oct 2025 23:38:11 -0700 Subject: [PATCH] logger: add mutex to deferred logger (#391) ## Link to GitHub Issue, if one exists [#390 ](https://github.com/spice2x/spice2x.github.io/pull/390) ## Description of change Just like the normal logger, deferred logging can be called from any component at any time, so accessing the vector needs to be guarded. ## Testing --- src/spice2x/avs/core.cpp | 2 +- src/spice2x/util/deferlog.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/spice2x/avs/core.cpp b/src/spice2x/avs/core.cpp index d9b4bcb..80c9110 100644 --- a/src/spice2x/avs/core.cpp +++ b/src/spice2x/avs/core.cpp @@ -1743,7 +1743,7 @@ namespace avs { deferredlogs::defer_error_messages({ "AVS filesystem initialization failure was previously detected during boot!", fmt::format(" ERROR: directory could not be created: {}", src_path.string().c_str()), - fmt::format(" this crash may have been caused by bad contents in {}", avs::core::CFG_PATH.c_str()), + fmt::format(" if you see a crash, it may have been caused by bad contents in {}", avs::core::CFG_PATH.c_str()), " fix the XML file and try again" }); } diff --git a/src/spice2x/util/deferlog.cpp b/src/spice2x/util/deferlog.cpp index 7471458..21dd314 100644 --- a/src/spice2x/util/deferlog.cpp +++ b/src/spice2x/util/deferlog.cpp @@ -13,15 +13,18 @@ namespace deferredlogs { " double check your spice audio options/patches, and try again" }; + std::mutex deferred_errors_mutex; std::vector> deferred_errors; void defer_error_messages(std::initializer_list messages) { + std::unique_lock lock(deferred_errors_mutex); deferred_errors.emplace_back(messages); } void dump_to_logger() { static std::once_flag printed; std::call_once(printed, []() { + std::unique_lock lock(deferred_errors_mutex); if (!deferred_errors.empty()) { log_warning("deferred_error", "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");