mirror of
https://github.com/ppy/osu.git
synced 2025-01-19 16:22:54 +08:00
Add exception on Apply() while loading
This commit is contained in:
parent
e7954ecb60
commit
36d2199a02
@ -28,12 +28,9 @@ namespace osu.Game.Rulesets.Objects.Pooling
|
|||||||
public TEntry? Entry
|
public TEntry? Entry
|
||||||
{
|
{
|
||||||
get => entry;
|
get => entry;
|
||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (LoadState < LoadState.Ready)
|
if (value != null)
|
||||||
entry = value;
|
|
||||||
else if (value != null)
|
|
||||||
Apply(value);
|
Apply(value);
|
||||||
else if (HasEntryApplied)
|
else if (HasEntryApplied)
|
||||||
free();
|
free();
|
||||||
@ -86,7 +83,7 @@ namespace osu.Game.Rulesets.Objects.Pooling
|
|||||||
|
|
||||||
// Apply the initial entry.
|
// Apply the initial entry.
|
||||||
if (Entry != null && !HasEntryApplied)
|
if (Entry != null && !HasEntryApplied)
|
||||||
Apply(Entry);
|
apply(Entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -95,16 +92,10 @@ namespace osu.Game.Rulesets.Objects.Pooling
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void Apply(TEntry entry)
|
public void Apply(TEntry entry)
|
||||||
{
|
{
|
||||||
if (HasEntryApplied)
|
if (LoadState == LoadState.Loading)
|
||||||
free();
|
throw new InvalidOperationException($"Cannot apply a new {nameof(TEntry)} while currently loading.");
|
||||||
|
|
||||||
this.entry = entry;
|
apply(entry);
|
||||||
entry.LifetimeChanged += setLifetimeFromEntry;
|
|
||||||
setLifetimeFromEntry(entry);
|
|
||||||
|
|
||||||
OnApply(entry);
|
|
||||||
|
|
||||||
HasEntryApplied = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected sealed override void FreeAfterUse()
|
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()
|
private void free()
|
||||||
{
|
{
|
||||||
Debug.Assert(Entry != null && HasEntryApplied);
|
Debug.Assert(Entry != null && HasEntryApplied);
|
||||||
|
Loading…
Reference in New Issue
Block a user