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

Fix nullref on test disposal

This commit is contained in:
Dean Herbert 2019-09-04 15:59:09 +09:00
parent 2983918f71
commit 8ea82123e4

View File

@ -4,6 +4,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Audio.Sample; using osu.Framework.Audio.Sample;
using osu.Framework.Bindables; using osu.Framework.Bindables;
@ -18,8 +19,10 @@ namespace osu.Game.Skinning
{ {
public class LegacySkin : Skin public class LegacySkin : Skin
{ {
[CanBeNull]
protected TextureStore Textures; protected TextureStore Textures;
[CanBeNull]
protected IResourceStore<SampleChannel> Samples; protected IResourceStore<SampleChannel> Samples;
public LegacySkin(SkinInfo skin, IResourceStore<byte[]> storage, AudioManager audioManager) public LegacySkin(SkinInfo skin, IResourceStore<byte[]> storage, AudioManager audioManager)
@ -37,9 +40,12 @@ namespace osu.Game.Skinning
else else
Configuration = new DefaultSkinConfiguration(); Configuration = new DefaultSkinConfiguration();
if (storage != null)
{
Samples = audioManager?.GetSampleStore(storage); Samples = audioManager?.GetSampleStore(storage);
Textures = new TextureStore(new TextureLoaderStore(storage)); Textures = new TextureStore(new TextureLoaderStore(storage));
} }
}
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)
{ {
@ -125,12 +131,12 @@ namespace osu.Game.Skinning
componentName = getFallbackName(componentName); componentName = getFallbackName(componentName);
float ratio = 2; float ratio = 2;
var texture = Textures.Get($"{componentName}@2x"); var texture = Textures?.Get($"{componentName}@2x");
if (texture == null) if (texture == null)
{ {
ratio = 1; ratio = 1;
texture = Textures.Get(componentName); texture = Textures?.Get(componentName);
} }
if (texture != null) if (texture != null)
@ -143,7 +149,7 @@ namespace osu.Game.Skinning
{ {
foreach (var lookup in sampleInfo.LookupNames) foreach (var lookup in sampleInfo.LookupNames)
{ {
var sample = Samples.Get(getFallbackName(lookup)); var sample = Samples?.Get(getFallbackName(lookup));
if (sample != null) if (sample != null)
return sample; return sample;
@ -151,7 +157,7 @@ namespace osu.Game.Skinning
if (sampleInfo is HitSampleInfo hsi) if (sampleInfo is HitSampleInfo hsi)
// Try fallback to non-bank samples. // Try fallback to non-bank samples.
return Samples.Get(hsi.Name); return Samples?.Get(hsi.Name);
return null; return null;
} }