osu/osu.Game/Screens/Select
Bartłomiej Dach cefbc76490
Fix selection being dropped when changing carousel sort mode from difficulty sort
Closes https://github.com/ppy/osu/issues/29738.

This "regressed" in https://github.com/ppy/osu/pull/29639, but if I
didn't know better, I'd go as far as saying that this looks like a .NET
bug, because the fact that PR broke it looks not sane.

The TL;DR on this is that before the pull in question, the offending
`.Contains()` check that this commit modifies was called on a
`List<BeatmapSetInfo>`. The pull changed the collection type to
`BeatmapSetInfo[]`. That said, the call is a LINQ call, so all good,
right?

Not really. First off, the default overload resolution order means that
the previous code would call `List<T>.Contains()`, and not
`Enumerable.Contains<T>()`. Then again, why would that matter? In both
cases `T` is still `BeatmapSetInfo`, right? Well... about that...

It is difficult to tell for sure what precisely is happening here,
because of what looks like runtime magic. The end *symptom* is that the
old code ended up calling `Array<BeatmapSetInfo>.IndexOf()`, and the new
code ends up calling... `Array<object>.IndexOf()`.

So while yes, `BeatmapSetInfo` implements `IEquatable` and
the expectation would be that `Equals<BeatmapSetInfo>()` should be
getting called, the type elision to `object` means that we're back to
reference equality semantics, because that's what
`EqualityComparer.Default<object>` is.

A five-minute github search across dotnet/runtime yields this:

	c4792a228e/src/coreclr/vm/array.cpp (L984-L990)

Now again, if I didn't know better, I'd see that "OPTIMIZATION:"
comment, see what transpired in this scenario, and call that
optimisation invalid, because it changes semantics. But I *probably*
know that the dotnet team knows better and am probably just going to
take it for what it is, because blame on that code looks to be years
old and it's probably not a new behaviour. (I haven't tested empirically
if it is.)

Instead the fix is just to tell the `.Contains()` method to use the
correct comparer.
2024-09-08 16:06:35 +02:00
..
Carousel Use for with exposed IReadOnlyList rather than making internal container public 2024-09-04 15:25:36 +09:00
Details
Filter
Leaderboards
Options
BeatmapCarousel.cs Fix selection being dropped when changing carousel sort mode from difficulty sort 2024-09-08 16:06:35 +02:00
BeatmapClearScoresDialog.cs
BeatmapDeleteDialog.cs
BeatmapDetailArea.cs
BeatmapDetailAreaDetailTabItem.cs
BeatmapDetailAreaLeaderboardTabItem.cs
BeatmapDetailAreaTabControl.cs
BeatmapDetailAreaTabItem.cs
BeatmapDetails.cs
BeatmapInfoWedge.cs Adjust song select info icon size slightly 2024-08-05 17:21:50 +09:00
BeatmapInfoWedgeBackground.cs
BeatmapInfoWedgeV2.cs
FilterControl.cs
FilterCriteria.cs
FilterQueryParser.cs Add 'yes'/'no' acronyms to the played= filter 2024-09-06 18:04:39 +09:00
Footer.cs
FooterButton.cs
FooterButtonMods.cs
FooterButtonOptions.cs
FooterButtonRandom.cs
LocalScoreDeleteDialog.cs
ModSpeedHotkeyHandler.cs
NoResultsPlaceholder.cs
PlayBeatmapDetailArea.cs
PlaySongSelect.cs
SkinDeleteDialog.cs
SongSelect.cs Fix some tests not always waiting long enough for beatmap loading 2024-08-29 18:42:43 +09:00
SongSelectTouchInputDetector.cs
WedgeBackground.cs