diff --git a/osu.Game.Rulesets.Karaoke.Tests/Bindables/BindableCultureInfoTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Bindables/BindableCultureInfoTest.cs index b68ee9410..6ebcf391d 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Bindables/BindableCultureInfoTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Bindables/BindableCultureInfoTest.cs @@ -47,4 +47,11 @@ public void TestParsingCultureInfo(int value, int expectedLcid) var actual = bindable.Value; Assert.AreEqual(expected, actual); } + + [TestCase("中文(简体)")] + public void TestParsingNotSupportedCultureInfo(string value) + { + var bindable = new BindableCultureInfo(); + Assert.DoesNotThrow(() => bindable.Parse(value)); + } } diff --git a/osu.Game.Rulesets.Karaoke/Bindables/BindableCultureInfo.cs b/osu.Game.Rulesets.Karaoke/Bindables/BindableCultureInfo.cs index 4a27275aa..7f59a2945 100644 --- a/osu.Game.Rulesets.Karaoke/Bindables/BindableCultureInfo.cs +++ b/osu.Game.Rulesets.Karaoke/Bindables/BindableCultureInfo.cs @@ -4,6 +4,7 @@ using System; using System.Globalization; using osu.Framework.Bindables; +using osu.Framework.Logging; using osu.Game.Rulesets.Karaoke.Utils; namespace osu.Game.Rulesets.Karaoke.Bindables; @@ -23,23 +24,34 @@ public override void Parse(object? input) return; } - switch (input) + try { - case string str: - Value = CultureInfoUtils.CreateLoadCultureInfoByCode(str); - break; - - case int lcid: - Value = CultureInfoUtils.CreateLoadCultureInfoById(lcid); - break; - - case CultureInfo cultureInfo: - Value = cultureInfo; - break; + switch (input) + { + case string str: + Value = CultureInfoUtils.CreateLoadCultureInfoByCode(str); + break; + + case int lcid: + Value = CultureInfoUtils.CreateLoadCultureInfoById(lcid); + break; + + case CultureInfo cultureInfo: + Value = cultureInfo; + break; + + default: + base.Parse(input); + break; + } + } + catch (Exception ex) + { + Value = null; - default: - base.Parse(input); - break; + // It might have issue that the culture info is not available in the system. + // Log it instead of throw exception. + Logger.Error(ex, $"Failed to parse {input} into {typeof(CultureInfo)}"); } }