From e536f1ad6d3bd1d00968eeddba4997ebda85218c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 21 Apr 2021 14:39:36 +0900 Subject: [PATCH] Add simple locking of resourceManagers dictionary for thread safety --- .../ResourceManagerLocalisationStore.cs | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/osu.Game/Localisation/ResourceManagerLocalisationStore.cs b/osu.Game/Localisation/ResourceManagerLocalisationStore.cs index e0f110aba9..7b21e1af42 100644 --- a/osu.Game/Localisation/ResourceManagerLocalisationStore.cs +++ b/osu.Game/Localisation/ResourceManagerLocalisationStore.cs @@ -31,18 +31,21 @@ namespace osu.Game.Localisation string ns = split[0]; string key = split[1]; - if (!resourceManagers.TryGetValue(ns, out var manager)) - resourceManagers[ns] = manager = new ResourceManager(ns, GetType().Assembly); + lock (resourceManagers) + { + if (!resourceManagers.TryGetValue(ns, out var manager)) + resourceManagers[ns] = manager = new ResourceManager(ns, GetType().Assembly); - try - { - return manager.GetString(key, EffectiveCulture); - } - catch (MissingManifestResourceException) - { - // in the case the manifest is missing, it is likely that the user is adding code-first implementations of new localisation namespaces. - // it's fine to ignore this as localisation will fallback to default values. - return null; + try + { + return manager.GetString(key, EffectiveCulture); + } + catch (MissingManifestResourceException) + { + // in the case the manifest is missing, it is likely that the user is adding code-first implementations of new localisation namespaces. + // it's fine to ignore this as localisation will fallback to default values. + return null; + } } }