System: Fix possible race condition in presence update

This commit is contained in:
Stenzek 2024-09-02 12:12:41 +10:00
parent 45291c5afe
commit 2e0b0d3963
No known key found for this signature in database
1 changed files with 7 additions and 8 deletions

View File

@ -4552,7 +4552,7 @@ void System::WarnAboutUnsafeSettings()
if (g_settings.enable_8mb_ram) if (g_settings.enable_8mb_ram)
{ {
append(ICON_EMOJI_WARNING, 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 else
@ -5886,15 +5886,14 @@ void System::UpdateRichPresence(bool update_session_time)
} }
} }
const auto lock = Achievements::GetLock();
std::string state_string; std::string state_string;
if (Achievements::HasRichPresence()) if (Achievements::HasRichPresence())
{ rp.state = (state_string = StringUtil::Ellipsise(Achievements::GetRichPresenceString(), 128)).c_str();
const auto lock = Achievements::GetLock();
state_string = StringUtil::Ellipsise(Achievements::GetRichPresenceString(), 128); if (const std::string& icon_url = Achievements::GetGameIconURL(); !icon_url.empty())
rp.state = state_string.c_str(); rp.largeImageKey = icon_url.c_str();
if (const std::string& icon_url = Achievements::GetGameIconURL(); !icon_url.empty())
rp.largeImageKey = icon_url.c_str();
}
dyn_libs::Discord_UpdatePresence(&rp); dyn_libs::Discord_UpdatePresence(&rp);
} }