mirror of
https://github.com/ppy/osu
synced 2024-12-14 10:57:41 +00:00
Add sample wrapper in LegacySkin to keep a reference and avoid GC death
This commit is contained in:
parent
4aff54412a
commit
880fe82073
@ -461,12 +461,43 @@ namespace osu.Game.Skinning
|
||||
var sample = Samples?.Get(lookup);
|
||||
|
||||
if (sample != null)
|
||||
return sample;
|
||||
return new LegacySkinSample(sample, this);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A sample wrapper which keeps a reference to the contained skin to avoid finalizer garbage collection of the managing SampleStore.
|
||||
/// </summary>
|
||||
private class LegacySkinSample : ISample
|
||||
{
|
||||
private readonly Sample sample;
|
||||
|
||||
[UsedImplicitly]
|
||||
private readonly LegacySkin skin;
|
||||
|
||||
public LegacySkinSample(Sample sample, LegacySkin skin)
|
||||
{
|
||||
this.sample = sample;
|
||||
this.skin = skin;
|
||||
}
|
||||
|
||||
public SampleChannel Play()
|
||||
{
|
||||
return sample.Play();
|
||||
}
|
||||
|
||||
public SampleChannel GetChannel()
|
||||
{
|
||||
return sample.GetChannel();
|
||||
}
|
||||
|
||||
public double Length => sample.Length;
|
||||
|
||||
public Bindable<int> PlaybackConcurrency => sample.PlaybackConcurrency;
|
||||
}
|
||||
|
||||
private IEnumerable<string> getLegacyLookupNames(HitSampleInfo hitSample)
|
||||
{
|
||||
var lookupNames = hitSample.LookupNames.SelectMany(getFallbackNames);
|
||||
|
Loading…
Reference in New Issue
Block a user