diff --git a/osu.Game/Skinning/RealmBackedResourceStore.cs b/osu.Game/Skinning/RealmBackedResourceStore.cs index 115d563575..e727a7e59a 100644 --- a/osu.Game/Skinning/RealmBackedResourceStore.cs +++ b/osu.Game/Skinning/RealmBackedResourceStore.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Linq; using System.Threading; using osu.Framework.Extensions; using osu.Framework.IO.Stores; @@ -21,6 +22,7 @@ namespace osu.Game.Skinning private Lazy> fileToStoragePathMapping; private readonly Live liveSource; + private readonly IDisposable? realmSubscription; public RealmBackedResourceStore(Live source, IResourceStore underlyingStore, RealmAccess? realm) : base(underlyingStore) @@ -29,9 +31,17 @@ namespace osu.Game.Skinning invalidateCache(); Debug.Assert(fileToStoragePathMapping != null); + + realmSubscription = realm?.RegisterForNotifications(r => r.All().Where(s => s.ID == source.ID), skinChanged); } - public void Invalidate() => invalidateCache(); + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + realmSubscription?.Dispose(); + } + + private void skinChanged(IRealmCollection sender, ChangeSet changes, Exception error) => invalidateCache(); protected override IEnumerable GetFilenames(string name) { diff --git a/osu.Game/Skinning/Skin.cs b/osu.Game/Skinning/Skin.cs index fb9914cd9e..4cd1d952db 100644 --- a/osu.Game/Skinning/Skin.cs +++ b/osu.Game/Skinning/Skin.cs @@ -54,8 +54,6 @@ namespace osu.Game.Skinning where TLookup : notnull where TValue : notnull; - public void InvalidateCaches() => realmBackedStorage?.Invalidate(); - private readonly RealmBackedResourceStore realmBackedStorage; /// @@ -206,6 +204,8 @@ namespace osu.Game.Skinning Textures?.Dispose(); Samples?.Dispose(); + + realmBackedStorage?.Dispose(); } #endregion diff --git a/osu.Game/Skinning/SkinManager.cs b/osu.Game/Skinning/SkinManager.cs index bafb088f68..5e85f9e4ca 100644 --- a/osu.Game/Skinning/SkinManager.cs +++ b/osu.Game/Skinning/SkinManager.cs @@ -16,7 +16,6 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.OpenGL.Textures; using osu.Framework.Graphics.Textures; using osu.Framework.IO.Stores; -using osu.Framework.Logging; using osu.Framework.Platform; using osu.Framework.Testing; using osu.Framework.Threading; @@ -27,7 +26,6 @@ using osu.Game.IO; using osu.Game.IO.Archives; using osu.Game.Models; using osu.Game.Overlays.Notifications; -using Realms; namespace osu.Game.Skinning { @@ -61,8 +59,6 @@ namespace osu.Game.Skinning private readonly IResourceStore userFiles; - private IDisposable currentSkinSubscription; - /// /// The default skin. /// @@ -104,12 +100,6 @@ namespace osu.Game.Skinning CurrentSkinInfo.ValueChanged += skin => { CurrentSkin.Value = skin.NewValue.PerformRead(GetSkin); - - scheduler.Add(() => - { - currentSkinSubscription?.Dispose(); - currentSkinSubscription = realm.RegisterForNotifications(r => r.All().Where(s => s.ID == skin.NewValue.ID), realmSkinChanged); - }); }; CurrentSkin.Value = DefaultSkin; @@ -122,12 +112,6 @@ namespace osu.Game.Skinning }; } - private void realmSkinChanged(IRealmCollection sender, ChangeSet changes, Exception error) where T : RealmObjectBase - { - Logger.Log("Detected a skin change"); - CurrentSkin.Value.InvalidateCaches(); - } - public void SelectRandomSkin() { realm.Run(r =>