1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-19 13:45:59 +08:00

Add exception on Apply() while loading

This commit is contained in:
smoogipoo 2021-06-18 19:20:57 +09:00
parent e7954ecb60
commit 36d2199a02

View File

@ -28,12 +28,9 @@ namespace osu.Game.Rulesets.Objects.Pooling
public TEntry? Entry
{
get => entry;
set
{
if (LoadState < LoadState.Ready)
entry = value;
else if (value != null)
if (value != null)
Apply(value);
else if (HasEntryApplied)
free();
@ -86,7 +83,7 @@ namespace osu.Game.Rulesets.Objects.Pooling
// Apply the initial entry.
if (Entry != null && !HasEntryApplied)
Apply(Entry);
apply(Entry);
}
/// <summary>
@ -95,16 +92,10 @@ namespace osu.Game.Rulesets.Objects.Pooling
/// </summary>
public void Apply(TEntry entry)
{
if (HasEntryApplied)
free();
if (LoadState == LoadState.Loading)
throw new InvalidOperationException($"Cannot apply a new {nameof(TEntry)} while currently loading.");
this.entry = entry;
entry.LifetimeChanged += setLifetimeFromEntry;
setLifetimeFromEntry(entry);
OnApply(entry);
HasEntryApplied = true;
apply(entry);
}
protected sealed override void FreeAfterUse()
@ -130,6 +121,20 @@ namespace osu.Game.Rulesets.Objects.Pooling
{
}
private void apply(TEntry entry)
{
if (HasEntryApplied)
free();
this.entry = entry;
entry.LifetimeChanged += setLifetimeFromEntry;
setLifetimeFromEntry(entry);
OnApply(entry);
HasEntryApplied = true;
}
private void free()
{
Debug.Assert(Entry != null && HasEntryApplied);