1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 19:53:23 +08:00

Fix missing null checks on selectedBeatmap fields in BeatmapCarousel

This commit is contained in:
Dean Herbert 2022-09-07 14:08:07 +09:00
parent 241d33d415
commit e18b524f8e

View File

@ -264,8 +264,11 @@ namespace osu.Game.Screens.Select
foreach (int i in changes.InsertedIndices) foreach (int i in changes.InsertedIndices)
UpdateBeatmapSet(sender[i].Detach()); UpdateBeatmapSet(sender[i].Detach());
if (changes.DeletedIndices.Length > 0) if (changes.DeletedIndices.Length > 0 && SelectedBeatmapInfo != null)
{ {
// If SelectedBeatmapInfo is non-null, the set should also be non-null.
Debug.Assert(SelectedBeatmapSet != null);
// To handle the beatmap update flow, attempt to track selection changes across delete-insert transactions. // To handle the beatmap update flow, attempt to track selection changes across delete-insert transactions.
// When an update occurs, the previous beatmap set is either soft or hard deleted. // When an update occurs, the previous beatmap set is either soft or hard deleted.
// Check if the current selection was potentially deleted by re-querying its validity. // Check if the current selection was potentially deleted by re-querying its validity.
@ -440,6 +443,9 @@ namespace osu.Game.Screens.Select
private void selectNextSet(int direction, bool skipDifficulties) private void selectNextSet(int direction, bool skipDifficulties)
{ {
if (selectedBeatmap == null || selectedBeatmapSet == null)
return;
var unfilteredSets = beatmapSets.Where(s => !s.Filtered.Value).ToList(); var unfilteredSets = beatmapSets.Where(s => !s.Filtered.Value).ToList();
var nextSet = unfilteredSets[(unfilteredSets.IndexOf(selectedBeatmapSet) + direction + unfilteredSets.Count) % unfilteredSets.Count]; var nextSet = unfilteredSets[(unfilteredSets.IndexOf(selectedBeatmapSet) + direction + unfilteredSets.Count) % unfilteredSets.Count];
@ -452,7 +458,7 @@ namespace osu.Game.Screens.Select
private void selectNextDifficulty(int direction) private void selectNextDifficulty(int direction)
{ {
if (selectedBeatmap == null) if (selectedBeatmap == null || selectedBeatmapSet == null)
return; return;
var unfilteredDifficulties = selectedBeatmapSet.Items.Where(s => !s.Filtered.Value).ToList(); var unfilteredDifficulties = selectedBeatmapSet.Items.Where(s => !s.Filtered.Value).ToList();
@ -481,7 +487,7 @@ namespace osu.Game.Screens.Select
if (!visibleSets.Any()) if (!visibleSets.Any())
return false; return false;
if (selectedBeatmap != null) if (selectedBeatmap != null && selectedBeatmapSet != null)
{ {
randomSelectedBeatmaps.Push(selectedBeatmap); randomSelectedBeatmaps.Push(selectedBeatmap);
@ -523,12 +529,14 @@ namespace osu.Game.Screens.Select
var beatmap = randomSelectedBeatmaps.Pop(); var beatmap = randomSelectedBeatmaps.Pop();
if (!beatmap.Filtered.Value) if (!beatmap.Filtered.Value)
{
if (selectedBeatmapSet != null)
{ {
if (RandomAlgorithm.Value == RandomSelectAlgorithm.RandomPermutation) if (RandomAlgorithm.Value == RandomSelectAlgorithm.RandomPermutation)
previouslyVisitedRandomSets.Remove(selectedBeatmapSet); previouslyVisitedRandomSets.Remove(selectedBeatmapSet);
if (selectedBeatmapSet != null)
playSpinSample(distanceBetween(beatmap, selectedBeatmapSet)); playSpinSample(distanceBetween(beatmap, selectedBeatmapSet));
}
select(beatmap); select(beatmap);
break; break;
@ -540,9 +548,13 @@ namespace osu.Game.Screens.Select
private void playSpinSample(double distance) private void playSpinSample(double distance)
{ {
var chan = spinSample.GetChannel(); var chan = spinSample?.GetChannel();
if (chan != null)
{
chan.Frequency.Value = 1f + Math.Min(1f, distance / visibleSetsCount); chan.Frequency.Value = 1f + Math.Min(1f, distance / visibleSetsCount);
chan.Play(); chan.Play();
}
randomSelectSample?.Play(); randomSelectSample?.Play();
} }