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

Test ruleset compatibility during initial startup to avoid runtime errors

As we continue to break the ruleset API, it makes more sense to
proactively check known changes and bail early during ruleset loading to
avoid a user experiencing a crash at a random point during execution.

This is a RFC and needs to be tested against known broken rulesets.
There might be some other calls we want to add in addition to the ones
I've listed.
This commit is contained in:
Dean Herbert 2022-08-18 16:03:37 +09:00
parent 7878231a73
commit e0edaf996f

View File

@ -7,6 +7,7 @@ using System.Linq;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Game.Beatmaps;
using osu.Game.Database;
namespace osu.Game.Rulesets
@ -83,17 +84,36 @@ namespace osu.Game.Rulesets
r.InstantiationInfo = instanceInfo.InstantiationInfo;
r.Available = true;
testRulesetCompatibility(r);
detachedRulesets.Add(r.Clone());
}
catch (Exception ex)
{
r.Available = false;
Logger.Log($"Could not load ruleset {r}: {ex.Message}");
Logger.Log($"Could not load ruleset {r.Name}. Please check for an update from the developer.", level: LogLevel.Error);
Logger.Log($"Ruleset load failed with {ex.Message}");
}
}
availableRulesets.AddRange(detachedRulesets.OrderBy(r => r));
});
}
private void testRulesetCompatibility(RulesetInfo rulesetInfo)
{
// do various operations to ensure that we are in a good state.
// if we can avoid loading the ruleset at this point (rather than erroring later in runtime) then that is preferred.
var instance = rulesetInfo.CreateInstance();
instance.CreateAllMods();
instance.CreateIcon();
instance.CreateResourceStore();
var beatmap = new Beatmap();
var converter = instance.CreateBeatmapConverter(beatmap);
instance.CreateBeatmapProcessor(converter.Convert());
}
}
}