Skip to content

Commit

Permalink
Merge pull request #26541 from peppy/fix-collection-dropdown-crash
Browse files Browse the repository at this point in the history
Fix collection dropdown crashing when all collections are deleted at once
  • Loading branch information
bdach committed Jan 15, 2024
2 parents cd9b665 + 96c472b commit fe8540b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ public void TestCollectionAddedToDropdown()
assertCollectionDropdownContains("2");
}

[Test]
public void TestCollectionsCleared()
{
AddStep("add collection", () => writeAndRefresh(r => r.Add(new BeatmapCollection(name: "1"))));
AddStep("add collection", () => writeAndRefresh(r => r.Add(new BeatmapCollection(name: "2"))));
AddStep("add collection", () => writeAndRefresh(r => r.Add(new BeatmapCollection(name: "3"))));

AddAssert("check count 5", () => control.ChildrenOfType<CollectionDropdown>().Single().ChildrenOfType<Menu.DrawableMenuItem>().Count(), () => Is.EqualTo(5));

AddStep("delete all collections", () => writeAndRefresh(r => r.RemoveAll<BeatmapCollection>()));

AddAssert("check count 2", () => control.ChildrenOfType<CollectionDropdown>().Single().ChildrenOfType<Menu.DrawableMenuItem>().Count(), () => Is.EqualTo(2));
}

[Test]
public void TestCollectionRemovedFromDropdown()
{
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Collections/CollectionDropdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private void collectionsChanged(IRealmCollection<BeatmapCollection> collections,
}
else
{
foreach (int i in changes.DeletedIndices)
foreach (int i in changes.DeletedIndices.OrderByDescending(i => i))
filters.RemoveAt(i + 1);

foreach (int i in changes.InsertedIndices)
Expand Down

0 comments on commit fe8540b

Please sign in to comment.