mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 07:42:57 +08:00
Fix game texture store being disposed by rulesets
This commit is contained in:
parent
fb9d2cb05c
commit
600b823a30
@ -10,6 +10,7 @@ using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
using osu.Framework.Audio.Track;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics.OpenGL.Textures;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Framework.IO.Stores;
|
||||
using osu.Game.Rulesets.Configuration;
|
||||
@ -46,12 +47,11 @@ namespace osu.Game.Rulesets.UI
|
||||
if (resources != null)
|
||||
{
|
||||
TextureStore = new TextureStore(new TextureLoaderStore(new NamespacedResourceStore<byte[]>(resources, @"Textures")));
|
||||
TextureStore.AddStore(parent.Get<TextureStore>());
|
||||
Cache(TextureStore);
|
||||
CacheAs(TextureStore = new FallbackTextureStore(TextureStore, parent.Get<TextureStore>()));
|
||||
|
||||
SampleStore = parent.Get<AudioManager>().GetSampleStore(new NamespacedResourceStore<byte[]>(resources, @"Samples"));
|
||||
SampleStore.PlaybackConcurrency = OsuGameBase.SAMPLE_CONCURRENCY;
|
||||
CacheAs<ISampleStore>(new FallbackSampleStore(SampleStore, parent.Get<ISampleStore>()));
|
||||
CacheAs(SampleStore = new FallbackSampleStore(SampleStore, parent.Get<ISampleStore>()));
|
||||
}
|
||||
|
||||
RulesetConfigManager = parent.Get<RulesetConfigCache>().GetConfigFor(ruleset);
|
||||
@ -82,6 +82,7 @@ namespace osu.Game.Rulesets.UI
|
||||
isDisposed = true;
|
||||
|
||||
SampleStore?.Dispose();
|
||||
TextureStore?.Dispose();
|
||||
RulesetConfigManager = null;
|
||||
}
|
||||
|
||||
@ -89,27 +90,24 @@ namespace osu.Game.Rulesets.UI
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A sample store which adds a fallback source.
|
||||
/// A sample store which adds a fallback source and prevents disposal of the fallback source.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is a temporary implementation to workaround ISampleStore limitations.
|
||||
/// </remarks>
|
||||
public class FallbackSampleStore : ISampleStore
|
||||
{
|
||||
private readonly ISampleStore primary;
|
||||
private readonly ISampleStore secondary;
|
||||
private readonly ISampleStore fallback;
|
||||
|
||||
public FallbackSampleStore(ISampleStore primary, ISampleStore secondary)
|
||||
public FallbackSampleStore(ISampleStore primary, ISampleStore fallback)
|
||||
{
|
||||
this.primary = primary;
|
||||
this.secondary = secondary;
|
||||
this.fallback = fallback;
|
||||
}
|
||||
|
||||
public SampleChannel Get(string name) => primary.Get(name) ?? secondary.Get(name);
|
||||
public SampleChannel Get(string name) => primary.Get(name) ?? fallback.Get(name);
|
||||
|
||||
public Task<SampleChannel> GetAsync(string name) => primary.GetAsync(name) ?? secondary.GetAsync(name);
|
||||
public Task<SampleChannel> GetAsync(string name) => primary.GetAsync(name) ?? fallback.GetAsync(name);
|
||||
|
||||
public Stream GetStream(string name) => primary.GetStream(name) ?? secondary.GetStream(name);
|
||||
public Stream GetStream(string name) => primary.GetStream(name) ?? fallback.GetStream(name);
|
||||
|
||||
public IEnumerable<string> GetAvailableResources() => throw new NotSupportedException();
|
||||
|
||||
@ -145,6 +143,31 @@ namespace osu.Game.Rulesets.UI
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
primary?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A texture store which adds a fallback source and prevents disposal of the fallback source.
|
||||
/// </summary>
|
||||
public class FallbackTextureStore : TextureStore
|
||||
{
|
||||
private readonly TextureStore primary;
|
||||
private readonly TextureStore fallback;
|
||||
|
||||
public FallbackTextureStore(TextureStore primary, TextureStore fallback)
|
||||
{
|
||||
this.primary = primary;
|
||||
this.fallback = fallback;
|
||||
}
|
||||
|
||||
public override Texture Get(string name, WrapMode wrapModeS, WrapMode wrapModeT)
|
||||
=> primary.Get(name, wrapModeS, wrapModeT) ?? fallback.Get(name, wrapModeS, wrapModeT);
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
primary?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user