From 6a4cc933603cf102108f1e354af006b05b871940 Mon Sep 17 00:00:00 2001 From: Aergwyn Date: Tue, 28 Nov 2017 21:26:13 +0100 Subject: [PATCH 1/7] fixes crash if all beatmaps of a set are hidden --- osu.Game/Screens/Select/BeatmapCarousel.cs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/osu.Game/Screens/Select/BeatmapCarousel.cs b/osu.Game/Screens/Select/BeatmapCarousel.cs index b0a636dfb3..e0f3137cec 100644 --- a/osu.Game/Screens/Select/BeatmapCarousel.cs +++ b/osu.Game/Screens/Select/BeatmapCarousel.cs @@ -45,7 +45,7 @@ namespace osu.Game.Screens.Select Task.Run(() => { - newGroups = value.Select(createGroup).ToList(); + newGroups = value.Select(createGroup).Where(g => g != null).ToList(); criteria.Filter(newGroups); }).ContinueWith(t => { @@ -124,16 +124,24 @@ namespace osu.Game.Screens.Select // todo: this method should be smarter as to not recreate panels that haven't changed, etc. var group = groups.Find(b => b.BeatmapSet.ID == set.ID); + BeatmapGroup newGroup; if (group == null) - return; + { + newGroup = createGroup(set); - int i = groups.IndexOf(group); - groups.RemoveAt(i); + if (newGroup != null) + groups.Add(newGroup); + } + else + { + int i = groups.IndexOf(group); + groups.RemoveAt(i); - var newGroup = createGroup(set); + newGroup = createGroup(set); - if (newGroup != null) - groups.Insert(i, newGroup); + if (newGroup != null) + groups.Insert(i, newGroup); + } bool hadSelection = selectedGroup == group; From 3bdf82d8df16ed910920c56938c3a74811a49602 Mon Sep 17 00:00:00 2001 From: Aergwyn Date: Tue, 28 Nov 2017 21:38:11 +0100 Subject: [PATCH 2/7] refactor newly added code to be less redundant --- osu.Game/Screens/Select/BeatmapCarousel.cs | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/osu.Game/Screens/Select/BeatmapCarousel.cs b/osu.Game/Screens/Select/BeatmapCarousel.cs index e0f3137cec..3f42ae11ac 100644 --- a/osu.Game/Screens/Select/BeatmapCarousel.cs +++ b/osu.Game/Screens/Select/BeatmapCarousel.cs @@ -124,23 +124,18 @@ namespace osu.Game.Screens.Select // todo: this method should be smarter as to not recreate panels that haven't changed, etc. var group = groups.Find(b => b.BeatmapSet.ID == set.ID); - BeatmapGroup newGroup; - if (group == null) - { - newGroup = createGroup(set); - - if (newGroup != null) - groups.Add(newGroup); - } - else - { - int i = groups.IndexOf(group); + int i = groups.IndexOf(group); + if (i >= 0) groups.RemoveAt(i); - newGroup = createGroup(set); + var newGroup = createGroup(set); - if (newGroup != null) + if (newGroup != null) + { + if (i >= 0) groups.Insert(i, newGroup); + else + groups.Add(newGroup); } bool hadSelection = selectedGroup == group; From d402222f1778fa5e9d43f91354a7d8a6238670fa Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 30 Nov 2017 05:05:07 +0900 Subject: [PATCH 3/7] Fix DisposeTrack and improve AsyncLazy to support disposal --- osu.Game/Beatmaps/WorkingBeatmap.cs | 63 +++++++++++++++++++++++++---- osu.Game/OsuGameBase.cs | 2 +- 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/osu.Game/Beatmaps/WorkingBeatmap.cs b/osu.Game/Beatmaps/WorkingBeatmap.cs index 2a8178882e..93ba51367a 100644 --- a/osu.Game/Beatmaps/WorkingBeatmap.cs +++ b/osu.Game/Beatmaps/WorkingBeatmap.cs @@ -31,7 +31,7 @@ namespace osu.Game.Beatmaps Mods.ValueChanged += mods => applyRateAdjustments(); beatmap = new AsyncLazy(populateBeatmap); - background = new AsyncLazy(populateBackground); + background = new AsyncLazy(populateBackground, b => b == null || !b.IsDisposed); track = new AsyncLazy(populateTrack); waveform = new AsyncLazy(populateWaveform); } @@ -99,10 +99,11 @@ namespace osu.Game.Beatmaps if (WaveformLoaded) Waveform?.Dispose(); } - public void DisposeTrack() - { - if (TrackLoaded) Track?.Dispose(); - } + /// + /// Eagerly dispose of the audio track associated with this (if any). + /// Accessing track again will load a fresh instance. + /// + public void RecycleTrack() => track.Recycle(); private void applyRateAdjustments(Track t = null) { @@ -114,11 +115,57 @@ namespace osu.Game.Beatmaps mod.ApplyToClock(t); } - public class AsyncLazy : Lazy> + public class AsyncLazy { - public AsyncLazy(Func valueFactory) - : base(() => Task.Run(valueFactory)) + private Lazy> lazy; + private readonly Func valueFactory; + private readonly Func stillValidFunction; + + public AsyncLazy(Func valueFactory, Func stillValidFunction = null) { + this.valueFactory = valueFactory; + this.stillValidFunction = stillValidFunction; + + init(); + } + + public void Recycle() + { + if (!IsValueCreated) return; + + (lazy.Value.Result as IDisposable)?.Dispose(); + + init(); + } + + public bool IsValueCreated + { + get + { + ensureValid(); + return lazy.IsValueCreated; + } + } + + public Task Value + { + get + { + ensureValid(); + return lazy.Value; + } + } + + private void ensureValid() + { + if (!lazy.IsValueCreated || (stillValidFunction?.Invoke(lazy.Value.Result) ?? true)) return; + + init(); + } + + private void init() + { + lazy = new Lazy>(() => Task.Run(valueFactory)); } } } diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 8eaa20f781..0ddff5e5aa 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -154,7 +154,7 @@ namespace osu.Game Debug.Assert(lastBeatmap != null); Debug.Assert(lastBeatmap.Track != null); - lastBeatmap.DisposeTrack(); + lastBeatmap.RecycleTrack(); } Audio.Track.AddItem(b.Track); From acb2cafa581da379df2ec85e6a69969f67694d13 Mon Sep 17 00:00:00 2001 From: Aergwyn Date: Wed, 29 Nov 2017 21:09:08 +0100 Subject: [PATCH 4/7] fix wedge not appearing --- osu.Game/Screens/Select/SongSelect.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index a0b788d777..b07e68f50e 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -263,10 +263,7 @@ namespace osu.Game.Screens.Select beatmapNoDebounce = beatmap; if (beatmap == null) - { - if (!Beatmap.IsDefault) - performLoad(); - } + performLoad(); else { if (beatmap.BeatmapSetInfoID == beatmapNoDebounce?.BeatmapSetInfoID) From 75327959356327ec3599a4348c0b3099b9e625ae Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 1 Dec 2017 22:43:49 +0900 Subject: [PATCH 5/7] Lock during validity checks --- osu.Game/Beatmaps/WorkingBeatmap.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/osu.Game/Beatmaps/WorkingBeatmap.cs b/osu.Game/Beatmaps/WorkingBeatmap.cs index 93ba51367a..8c96074352 100644 --- a/osu.Game/Beatmaps/WorkingBeatmap.cs +++ b/osu.Game/Beatmaps/WorkingBeatmap.cs @@ -121,6 +121,8 @@ namespace osu.Game.Beatmaps private readonly Func valueFactory; private readonly Func stillValidFunction; + private readonly object initLock = new object(); + public AsyncLazy(Func valueFactory, Func stillValidFunction = null) { this.valueFactory = valueFactory; @@ -134,7 +136,6 @@ namespace osu.Game.Beatmaps if (!IsValueCreated) return; (lazy.Value.Result as IDisposable)?.Dispose(); - init(); } @@ -158,9 +159,11 @@ namespace osu.Game.Beatmaps private void ensureValid() { - if (!lazy.IsValueCreated || (stillValidFunction?.Invoke(lazy.Value.Result) ?? true)) return; - - init(); + lock (initLock) + { + if (!lazy.IsValueCreated || (stillValidFunction?.Invoke(lazy.Value.Result) ?? true)) return; + init(); + } } private void init() From ee75f90ab33545e51ab8a919b88a3a000eb60ae5 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 1 Dec 2017 22:44:25 +0900 Subject: [PATCH 6/7] Update framework --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index 87d68cda00..cc013fc406 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 87d68cda0015d51dc3da56d2322fa10d399fc4ed +Subproject commit cc013fc4063dda0843f38c1c73568a413abcf229 From de94082b1e142174f8d2275c3369b990df0f3ca3 Mon Sep 17 00:00:00 2001 From: gtensha Date: Fri, 1 Dec 2017 18:10:39 +0100 Subject: [PATCH 7/7] Fix filename casing to compile on Linux --- osu.Game/osu.Game.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index f814cbb3d3..8b6bdefc6c 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -280,7 +280,7 @@ 20171025071459_AddMissingIndexRules.cs - + 20171119065731_AddBeatmapOnlineIDUniqueConstraint.cs