From 0db31ca61538f1da01601c703cd84c9cede11da5 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 2 Sep 2024 12:12:41 +1000 Subject: [PATCH] System: Fix possible race condition in presence update --- src/core/system.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/core/system.cpp b/src/core/system.cpp index a5781dfda..82fb7dc9e 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -4552,7 +4552,7 @@ void System::WarnAboutUnsafeSettings() if (g_settings.enable_8mb_ram) { append(ICON_EMOJI_WARNING, - TRANSLATE_SV("System", "8MB RAM is enabled, this may be incompatible with some games.")); + TRANSLATE_SV("System", "8MB RAM is enabled, this may be incompatible with some games.")); } } else @@ -5886,15 +5886,14 @@ void System::UpdateRichPresence(bool update_session_time) } } + const auto lock = Achievements::GetLock(); + std::string state_string; if (Achievements::HasRichPresence()) - { - const auto lock = Achievements::GetLock(); - state_string = StringUtil::Ellipsise(Achievements::GetRichPresenceString(), 128); - rp.state = state_string.c_str(); - if (const std::string& icon_url = Achievements::GetGameIconURL(); !icon_url.empty()) - rp.largeImageKey = icon_url.c_str(); - } + rp.state = (state_string = StringUtil::Ellipsise(Achievements::GetRichPresenceString(), 128)).c_str(); + + if (const std::string& icon_url = Achievements::GetGameIconURL(); !icon_url.empty()) + rp.largeImageKey = icon_url.c_str(); dyn_libs::Discord_UpdatePresence(&rp); }