From 7d8fe5117834aeb296cd6be28a89effa2bb9083f Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Mon, 8 Apr 2024 23:25:45 +0900 Subject: [PATCH] Fix possible crash due to race in DiscordRichPresence --- osu.Desktop/DiscordRichPresence.cs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/osu.Desktop/DiscordRichPresence.cs b/osu.Desktop/DiscordRichPresence.cs index 7553924d1b..ed9d4ca2d2 100644 --- a/osu.Desktop/DiscordRichPresence.cs +++ b/osu.Desktop/DiscordRichPresence.cs @@ -36,8 +36,6 @@ internal partial class DiscordRichPresence : Component [Resolved] private IBindable ruleset { get; set; } = null!; - private IBindable user = null!; - [Resolved] private IAPIProvider api { get; set; } = null!; @@ -50,9 +48,11 @@ internal partial class DiscordRichPresence : Component [Resolved] private MultiplayerClient multiplayerClient { get; set; } = null!; + [Resolved] + private OsuConfigManager config { get; set; } = null!; + private readonly IBindable status = new Bindable(); private readonly IBindable activity = new Bindable(); - private readonly Bindable privacyMode = new Bindable(); private readonly RichPresence presence = new RichPresence @@ -65,8 +65,10 @@ internal partial class DiscordRichPresence : Component }, }; + private IBindable? user; + [BackgroundDependencyLoader] - private void load(OsuConfigManager config) + private void load() { client = new DiscordRpcClient(client_id) { @@ -87,6 +89,13 @@ private void load(OsuConfigManager config) client.OnJoin += onJoin; } + client.Initialize(); + } + + protected override void LoadComplete() + { + base.LoadComplete(); + config.BindWith(OsuSetting.DiscordRichPresence, privacyMode); user = api.LocalUser.GetBoundCopy(); @@ -104,8 +113,6 @@ private void load(OsuConfigManager config) activity.BindValueChanged(_ => schedulePresenceUpdate()); privacyMode.BindValueChanged(_ => schedulePresenceUpdate()); multiplayerClient.RoomUpdated += onRoomUpdated; - - client.Initialize(); } private void onReady(object _, ReadyMessage __) @@ -146,6 +153,9 @@ private void schedulePresenceUpdate() private void updatePresence(bool hideIdentifiableInformation) { + if (user == null) + return; + // user activity if (activity.Value != null) {