diff --git a/osu.Game/Overlays/Toolbar/ToolbarButton.cs b/osu.Game/Overlays/Toolbar/ToolbarButton.cs index 221282ef13..5b75b8419c 100644 --- a/osu.Game/Overlays/Toolbar/ToolbarButton.cs +++ b/osu.Game/Overlays/Toolbar/ToolbarButton.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using System.Linq; using osu.Framework.Allocation; using osu.Framework.Extensions.Color4Extensions; @@ -77,6 +78,8 @@ namespace osu.Game.Overlays.Toolbar protected readonly Container BackgroundContent; + private IDisposable? realmSubscription; + [Resolved] private RealmAccess realm { get; set; } = null!; @@ -184,7 +187,8 @@ namespace osu.Game.Overlays.Toolbar { if (Hotkey != null) { - realm.SubscribeToPropertyChanged(r => r.All().FirstOrDefault(rkb => rkb.RulesetName == null && rkb.ActionInt == (int)Hotkey.Value), kb => kb.KeyCombinationString, updateKeyBindingTooltip); + realmSubscription = realm.SubscribeToPropertyChanged(r => r.All().FirstOrDefault(rkb => rkb.RulesetName == null && rkb.ActionInt == (int)Hotkey.Value), + kb => kb.KeyCombinationString, updateKeyBindingTooltip); } } @@ -234,6 +238,13 @@ namespace osu.Game.Overlays.Toolbar ? $" ({keyBindingString})" : string.Empty; } + + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + + realmSubscription?.Dispose(); + } } public partial class OpaqueBackground : Container