Softly-handle infinite loops in mania beatmap conversion

This commit is contained in:
smoogipoo
2018-08-14 16:40:17 +09:00
parent da01501a1c
commit 2019a89a08
4 changed files with 57 additions and 12 deletions

View File

@ -3,6 +3,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using JetBrains.Annotations;
using osu.Framework.Logging;
using osu.Game.Rulesets.Objects;
namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns
@ -12,6 +15,8 @@ namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns
/// </summary>
internal abstract class PatternGenerator
{
private const int max_rng_iterations = 100;
/// <summary>
/// The last pattern.
/// </summary>
@ -42,6 +47,21 @@ namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns
TotalColumns = Beatmap.TotalColumns;
}
protected void RunWhile([InstantHandle] Func<bool> condition, Action action)
{
int iterations = 0;
while (condition() && iterations++ < max_rng_iterations)
action();
if (iterations < max_rng_iterations)
return;
// Generate + log an error/stacktrace
Logger.Log($"Allowable time exceeded for hitobject generation:\n{new StackTrace(0)}", level: LogLevel.Error);
}
/// <summary>
/// Generates the patterns for <see cref="HitObject"/>, each filled with hit objects.
/// </summary>