1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 22:07:25 +08:00

Fix thread safety of KeyBindingStore.GetReadableKeyCombinationsFor

This commit is contained in:
Dean Herbert 2021-06-18 17:01:51 +09:00
parent c369beeaaa
commit d06e52505a
2 changed files with 16 additions and 9 deletions

View File

@ -26,16 +26,23 @@ namespace osu.Game.Input
/// </summary>
/// <param name="globalAction">The action to lookup.</param>
/// <returns>A set of display strings for all the user's key configuration for the action.</returns>
public IEnumerable<string> GetReadableKeyCombinationsFor(GlobalAction globalAction)
public IReadOnlyList<string> GetReadableKeyCombinationsFor(GlobalAction globalAction)
{
foreach (var action in realmFactory.Context.All<RealmKeyBinding>().Where(b => (GlobalAction)b.ActionInt == globalAction))
{
string str = action.KeyCombination.ReadableString();
List<string> combinations = new List<string>();
// even if found, the readable string may be empty for an unbound action.
if (str.Length > 0)
yield return str;
using (var context = realmFactory.GetForRead())
{
foreach (var action in context.Realm.All<RealmKeyBinding>().Where(b => (GlobalAction)b.ActionInt == globalAction))
{
string str = action.KeyCombination.ReadableString();
// even if found, the readable string may be empty for an unbound action.
if (str.Length > 0)
combinations.Add(str);
}
}
return combinations;
}
/// <summary>

View File

@ -608,9 +608,9 @@ namespace osu.Game
LocalConfig.LookupKeyBindings = l =>
{
var combinations = KeyBindingStore.GetReadableKeyCombinationsFor(l).ToArray();
var combinations = KeyBindingStore.GetReadableKeyCombinationsFor(l);
if (combinations.Length == 0)
if (combinations.Count == 0)
return "none";
return string.Join(" or ", combinations);