Merge pull request #11500 from peppy/fix-skin-dropdown-update-crash

This commit is contained in:
Bartłomiej Dach 2021-01-30 13:34:00 +01:00 committed by GitHub
commit fec3bd898e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -108,7 +108,7 @@ namespace osu.Game.Overlays.Settings.Sections
if (skinDropdown.Items.All(s => s.ID != configBindable.Value))
configBindable.Value = 0;
configBindable.BindValueChanged(id => dropdownBindable.Value = skinDropdown.Items.Single(s => s.ID == id.NewValue), true);
configBindable.BindValueChanged(id => Scheduler.AddOnce(updateSelectedSkinFromConfig), true);
dropdownBindable.BindValueChanged(skin =>
{
if (skin.NewValue == random_skin_info)
@ -121,6 +121,23 @@ namespace osu.Game.Overlays.Settings.Sections
});
}
private void updateSelectedSkinFromConfig()
{
int id = configBindable.Value;
var skin = skinDropdown.Items.FirstOrDefault(s => s.ID == id);
if (skin == null)
{
// there may be a thread race condition where an item is selected that hasn't yet been added to the dropdown.
// to avoid adding complexity, let's just ensure the item is added so we can perform the selection.
skin = skins.Query(s => s.ID == id);
addItem(skin);
}
dropdownBindable.Value = skin;
}
private void updateItems()
{
skinItems = skins.GetAllUsableSkins();
@ -132,14 +149,14 @@ namespace osu.Game.Overlays.Settings.Sections
private void itemUpdated(ValueChangedEvent<WeakReference<SkinInfo>> weakItem)
{
if (weakItem.NewValue.TryGetTarget(out var item))
{
Schedule(() =>
Schedule(() => addItem(item));
}
private void addItem(SkinInfo item)
{
List<SkinInfo> newDropdownItems = skinDropdown.Items.Where(i => !i.Equals(item)).Append(item).ToList();
sortUserSkins(newDropdownItems);
skinDropdown.Items = newDropdownItems;
});
}
}
private void itemRemoved(ValueChangedEvent<WeakReference<SkinInfo>> weakItem)