1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 08:32:57 +08:00

Fix cross-thread list manipulation in SkinProvidingContainer

This commit is contained in:
Dean Herbert 2021-10-12 11:28:11 +09:00
parent 696193198a
commit df83f0db08

View File

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Audio.Sample;
@ -43,7 +44,7 @@ namespace osu.Game.Skinning
/// <summary>
/// A dictionary mapping each <see cref="ISkin"/> source to a wrapper which handles lookup allowances.
/// </summary>
private readonly List<(ISkin skin, DisableableSkinSource wrapped)> skinSources = new List<(ISkin, DisableableSkinSource)>();
private (ISkin skin, DisableableSkinSource wrapped)[] skinSources = Array.Empty<(ISkin skin, DisableableSkinSource wrapped)>();
/// <summary>
/// Constructs a new <see cref="SkinProvidingContainer"/> initialised with a single skin source.
@ -173,32 +174,24 @@ namespace osu.Game.Skinning
/// <param name="skin">The skin to add.</param>
protected void AddSource(ISkin skin)
{
skinSources.Add((skin, new DisableableSkinSource(skin, this)));
skinSources = skinSources.Append((skin, new DisableableSkinSource(skin, this))).ToArray();
if (skin is ISkinSource source)
source.SourceChanged += TriggerSourceChanged;
}
/// <summary>
/// Remove a skin from this provider.
/// </summary>
/// <param name="skin">The skin to remove.</param>
protected void RemoveSource(ISkin skin)
{
if (skinSources.RemoveAll(s => s.skin == skin) == 0)
return;
if (skin is ISkinSource source)
source.SourceChanged -= TriggerSourceChanged;
}
/// <summary>
/// Clears all skin sources.
/// </summary>
protected void ResetSources()
{
foreach (var i in skinSources.ToArray())
RemoveSource(i.skin);
foreach (var skin in skinSources)
{
if (skin.skin is ISkinSource source)
source.SourceChanged -= TriggerSourceChanged;
}
skinSources = Array.Empty<(ISkin skin, DisableableSkinSource wrapped)>();
}
/// <summary>