Fallback to default ruleset star rating if conversion fails

This commit is contained in:
smoogipoo 2020-10-12 16:31:42 +09:00
parent 8431a5a23c
commit ccf7e2c49a
1 changed files with 20 additions and 0 deletions

View File

@ -13,10 +13,12 @@
using osu.Framework.Bindables;
using osu.Framework.Graphics.Containers;
using osu.Framework.Lists;
using osu.Framework.Logging;
using osu.Framework.Threading;
using osu.Framework.Utils;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.UI;
namespace osu.Game.Beatmaps
{
@ -238,6 +240,24 @@ private StarDifficulty computeDifficulty(in DifficultyCacheLookup key, BeatmapIn
return difficultyCache[key] = new StarDifficulty(attributes.StarRating, attributes.MaxCombo);
}
catch (BeatmapInvalidForRulesetException e)
{
// Conversion has failed for the given ruleset, so return the difficulty in the beatmap's default ruleset.
// Ensure the beatmap's default ruleset isn't the one already being converted to.
// This shouldn't happen as it means something went seriously wrong, but if it does an endless loop should be avoided.
if (rulesetInfo.Equals(beatmapInfo.Ruleset))
{
Logger.Error(e, $"Failed to convert {beatmapInfo.OnlineBeatmapID} to the beatmap's default ruleset ({beatmapInfo.Ruleset}).");
return difficultyCache[key] = new StarDifficulty();
}
// Check the cache first because this is now a different ruleset than the one previously guarded against.
if (tryGetExisting(beatmapInfo, beatmapInfo.Ruleset, Array.Empty<Mod>(), out var existingDefault, out var existingDefaultKey))
return existingDefault;
return computeDifficulty(existingDefaultKey, beatmapInfo, beatmapInfo.Ruleset);
}
catch
{
return difficultyCache[key] = new StarDifficulty();