mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 08:20:00 +09:00
Softly-handle infinite loops in mania beatmap conversion
This commit is contained in:
@ -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>
|
||||
|
Reference in New Issue
Block a user