mirror of
https://github.com/SK-la/osu-framework.git
synced 2026-03-13 11:20:31 +00:00
Fix multiple cases of using objects which may be disposed
This commit is contained in:
@@ -41,16 +41,22 @@ namespace osu.Framework.Benchmarks
|
||||
[Benchmark]
|
||||
public void BenchmarkRawCachingReuse()
|
||||
{
|
||||
using (var store = new RawCachingGlyphStore(baseResources, font_name) { CacheStorage = sharedTemp })
|
||||
using (var store = new RawCachingGlyphStore(baseResources, font_name))
|
||||
{
|
||||
store.CacheStorage = sharedTemp;
|
||||
runFor(store);
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark(Baseline = true)]
|
||||
public void BenchmarkRawCaching()
|
||||
{
|
||||
using (var temp = new TemporaryNativeStorage("fontstore-test" + Guid.NewGuid()))
|
||||
using (var store = new RawCachingGlyphStore(baseResources, font_name) { CacheStorage = temp })
|
||||
using (var store = new RawCachingGlyphStore(baseResources, font_name))
|
||||
{
|
||||
store.CacheStorage = temp;
|
||||
runFor(store);
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
|
||||
@@ -47,13 +47,17 @@ namespace osu.Framework.Tests.IO
|
||||
[Test]
|
||||
public void TestNoCrashOnMissingResources()
|
||||
{
|
||||
using (var glyphStore = new RawCachingGlyphStore(fontResourceStore, "DoesntExist") { CacheStorage = storage })
|
||||
using (var fontStore = new FontStore(new DummyRenderer(), glyphStore, 100))
|
||||
using (var glyphStore = new RawCachingGlyphStore(fontResourceStore, "DoesntExist"))
|
||||
{
|
||||
Assert.That(glyphStore.Get('a'), Is.Null);
|
||||
glyphStore.CacheStorage = storage;
|
||||
|
||||
Assert.That(fontStore.Get("DoesntExist", 'a'), Is.Null);
|
||||
Assert.That(fontStore.Get("OtherAttempt", 'a'), Is.Null);
|
||||
using (var fontStore = new FontStore(new DummyRenderer(), glyphStore, 100))
|
||||
{
|
||||
Assert.That(glyphStore.Get('a'), Is.Null);
|
||||
|
||||
Assert.That(fontStore.Get("DoesntExist", 'a'), Is.Null);
|
||||
Assert.That(fontStore.Get("OtherAttempt", 'a'), Is.Null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,12 +33,17 @@ namespace osu.Framework.IO.Stores
|
||||
return stream?.ReadAllBytesToArray();
|
||||
}
|
||||
|
||||
public virtual Task<byte[]> GetAsync(string name, CancellationToken cancellationToken = default)
|
||||
public virtual async Task<byte[]> GetAsync(string name, CancellationToken cancellationToken = default)
|
||||
{
|
||||
this.LogIfNonBackgroundThread(name);
|
||||
|
||||
using (Stream stream = storage.GetStream(name))
|
||||
return stream?.ReadAllBytesToArrayAsync(cancellationToken);
|
||||
{
|
||||
if (stream == null)
|
||||
return null;
|
||||
|
||||
return await stream.ReadAllBytesToArrayAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
public Stream GetStream(string name)
|
||||
|
||||
Reference in New Issue
Block a user