1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 01:52:55 +08:00

Dispose enumerators for safety

This commit is contained in:
smoogipoo 2020-04-17 14:40:29 +09:00
parent 4e4fe5cc90
commit 2dee5e03e3

View File

@ -39,8 +39,8 @@ namespace osu.Game.Rulesets.Osu.UI
{
DrawableHitObject blockingObject = null;
var enumerator = new HitObjectEnumerator(hitObjectContainer, hitObject.HitObject.StartTime);
using (var enumerator = new HitObjectEnumerator(hitObjectContainer, hitObject.HitObject.StartTime))
{
while (enumerator.MoveNext())
{
Debug.Assert(enumerator.Current != null);
@ -48,6 +48,7 @@ namespace osu.Game.Rulesets.Osu.UI
if (hitObjectCanBlockFutureHits(enumerator.Current))
blockingObject = enumerator.Current;
}
}
// If there is no previous hitobject, allow the hit.
if (blockingObject == null)
@ -76,8 +77,8 @@ namespace osu.Game.Rulesets.Osu.UI
if (!IsHittable(hitObject, hitObject.HitObject.StartTime + hitObject.Result.TimeOffset))
throw new InvalidOperationException($"A {hitObject} was hit before it become hittable!");
var enumerator = new HitObjectEnumerator(hitObjectContainer, hitObject.HitObject.StartTime);
using (var enumerator = new HitObjectEnumerator(hitObjectContainer, hitObject.HitObject.StartTime))
{
while (enumerator.MoveNext())
{
Debug.Assert(enumerator.Current != null);
@ -89,6 +90,7 @@ namespace osu.Game.Rulesets.Osu.UI
((DrawableOsuHitObject)enumerator.Current).MissForcefully();
}
}
}
/// <summary>
/// Whether a <see cref="HitObject"/> blocks hits on future <see cref="HitObject"/>s until its start time is reached.
@ -180,6 +182,7 @@ namespace osu.Game.Rulesets.Osu.UI
public void Dispose()
{
hitObjectEnumerator?.Dispose();
}
}
}