fix crash if any amount of maps were restored from main menu

also fixes preview not playing if an entire set is restored
This commit is contained in:
Aergwyn 2017-12-04 11:47:27 +01:00
parent 58777a9674
commit 011223048b
2 changed files with 21 additions and 13 deletions

View File

@ -34,7 +34,6 @@ namespace osu.Game.Screens.Select
public IEnumerable<BeatmapSetInfo> Beatmaps public IEnumerable<BeatmapSetInfo> Beatmaps
{ {
get { return groups.Select(g => g.BeatmapSet); } get { return groups.Select(g => g.BeatmapSet); }
set set
{ {
scrollableContent.Clear(false); scrollableContent.Clear(false);
@ -44,15 +43,14 @@ namespace osu.Game.Screens.Select
List<BeatmapGroup> newGroups = null; List<BeatmapGroup> newGroups = null;
Task.Run(() => Task.Run(() =>
{
newGroups = value.Select(createGroup).Where(g => g != null).ToList();
criteria.Filter(newGroups);
}).ContinueWith(t =>
{ {
Schedule(() => Schedule(() =>
{ {
newGroups = value.Select(createGroup).Where(g => g != null).ToList();
criteria.Filter(newGroups);
foreach (var g in newGroups) foreach (var g in newGroups)
if (g != null) addGroup(g); addGroup(g);
computeYPositions(); computeYPositions();
BeatmapsChanged?.Invoke(); BeatmapsChanged?.Invoke();
@ -135,7 +133,7 @@ namespace osu.Game.Screens.Select
if (i >= 0) if (i >= 0)
groups.Insert(i, newGroup); groups.Insert(i, newGroup);
else else
groups.Add(newGroup); addGroup(newGroup);
} }
bool hadSelection = selectedGroup == group; bool hadSelection = selectedGroup == group;
@ -149,8 +147,10 @@ namespace osu.Game.Screens.Select
if (hadSelection && newGroup != null) if (hadSelection && newGroup != null)
{ {
var newSelection = var newSelection =
newGroup.BeatmapPanels.Find(p => p.Beatmap.ID == selectedPanel?.Beatmap.ID) ?? newGroup.BeatmapPanels.Find(p => p.Beatmap.ID == selectedPanel?.Beatmap.ID);
newGroup.BeatmapPanels[Math.Min(newGroup.BeatmapPanels.Count - 1, group.BeatmapPanels.IndexOf(selectedPanel))];
if(newSelection == null && group != null && selectedPanel != null)
newSelection = newGroup.BeatmapPanels[Math.Min(newGroup.BeatmapPanels.Count - 1, group.BeatmapPanels.IndexOf(selectedPanel))];
selectGroup(newGroup, newSelection); selectGroup(newGroup, newSelection);
} }
@ -350,6 +350,8 @@ namespace osu.Game.Screens.Select
private BeatmapGroup createGroup(BeatmapSetInfo beatmapSet) private BeatmapGroup createGroup(BeatmapSetInfo beatmapSet)
{ {
beatmapSet = manager.Refresh(beatmapSet);
if (beatmapSet.Beatmaps.All(b => b.Hidden)) if (beatmapSet.Beatmaps.All(b => b.Hidden))
return null; return null;
@ -381,6 +383,10 @@ namespace osu.Game.Screens.Select
private void addGroup(BeatmapGroup group) private void addGroup(BeatmapGroup group)
{ {
// prevent duplicates by concurrent independent actions trying to add a group
if (groups.Any(g => g.BeatmapSet.ID == group.BeatmapSet.ID))
return;
groups.Add(group); groups.Add(group);
panels.Add(group.Header); panels.Add(group.Header);
panels.AddRange(group.BeatmapPanels); panels.AddRange(group.BeatmapPanels);
@ -478,7 +484,8 @@ namespace osu.Game.Screens.Select
if (panel == null) if (panel == null)
panel = group.BeatmapPanels.First(); panel = group.BeatmapPanels.First();
if (selectedPanel == panel) return; if (selectedPanel == panel)
return;
Trace.Assert(group.BeatmapPanels.Contains(panel), @"Selected panel must be in provided group"); Trace.Assert(group.BeatmapPanels.Contains(panel), @"Selected panel must be in provided group");
@ -490,7 +497,8 @@ namespace osu.Game.Screens.Select
panel.State = PanelSelectedState.Selected; panel.State = PanelSelectedState.Selected;
if (selectedPanel == panel) return; if (selectedPanel == panel)
return;
selectedPanel = panel; selectedPanel = panel;
selectedGroup = group; selectedGroup = group;

View File

@ -255,11 +255,11 @@ namespace osu.Game.Screens.Select
UpdateBeatmap(Beatmap.Value); UpdateBeatmap(Beatmap.Value);
}; };
selectionChangedDebounce?.Cancel();
if (beatmap?.Equals(beatmapNoDebounce) == true) if (beatmap?.Equals(beatmapNoDebounce) == true)
return; return;
selectionChangedDebounce?.Cancel();
beatmapNoDebounce = beatmap; beatmapNoDebounce = beatmap;
if (beatmap == null) if (beatmap == null)