From 9c5423734a30587063c9a1375eeccb6243cc0d78 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 16 Mar 2020 11:33:26 +0900 Subject: [PATCH] Throw timeout exceptions instead --- osu.Game/Beatmaps/WorkingBeatmap.cs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/osu.Game/Beatmaps/WorkingBeatmap.cs b/osu.Game/Beatmaps/WorkingBeatmap.cs index bdcfc058b4..dd4f893ac2 100644 --- a/osu.Game/Beatmaps/WorkingBeatmap.cs +++ b/osu.Game/Beatmaps/WorkingBeatmap.cs @@ -100,7 +100,9 @@ namespace osu.Game.Beatmaps // Apply conversion mods foreach (var mod in mods.OfType()) { - cancellationSource.Token.ThrowIfCancellationRequested(); + if (cancellationSource.IsCancellationRequested) + throw new BeatmapLoadTimeoutException(BeatmapInfo); + mod.ApplyToBeatmapConverter(converter); } @@ -115,7 +117,9 @@ namespace osu.Game.Beatmaps foreach (var mod in mods.OfType()) { - cancellationSource.Token.ThrowIfCancellationRequested(); + if (cancellationSource.IsCancellationRequested) + throw new BeatmapLoadTimeoutException(BeatmapInfo); + mod.ApplyToDifficulty(converted.BeatmapInfo.BaseDifficulty); } } @@ -127,7 +131,9 @@ namespace osu.Game.Beatmaps // Compute default values for hitobjects, including creating nested hitobjects in-case they're needed foreach (var obj in converted.HitObjects) { - cancellationSource.Token.ThrowIfCancellationRequested(); + if (cancellationSource.IsCancellationRequested) + throw new BeatmapLoadTimeoutException(BeatmapInfo); + obj.ApplyDefaults(converted.ControlPointInfo, converted.BeatmapInfo.BaseDifficulty); } @@ -135,7 +141,9 @@ namespace osu.Game.Beatmaps { foreach (var obj in converted.HitObjects) { - cancellationSource.Token.ThrowIfCancellationRequested(); + if (cancellationSource.IsCancellationRequested) + throw new BeatmapLoadTimeoutException(BeatmapInfo); + mod.ApplyToHitObject(obj); } } @@ -315,5 +323,13 @@ namespace osu.Game.Beatmaps private void recreate() => lazy = new Lazy(valueFactory, LazyThreadSafetyMode.ExecutionAndPublication); } + + private class BeatmapLoadTimeoutException : TimeoutException + { + public BeatmapLoadTimeoutException(BeatmapInfo beatmapInfo) + : base($"Timed out while loading beatmap ({beatmapInfo}).") + { + } + } } }