mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 12:17:26 +08:00
Fix thread safety issue when accessing files in beatmap (zip) files.
This commit is contained in:
parent
2ee5e2efb7
commit
8fe63689a4
@ -46,13 +46,10 @@ namespace osu.Desktop.VisualTests.Tests
|
||||
|
||||
Add(new Player
|
||||
{
|
||||
Beatmap = new WorkingBeatmap
|
||||
Beatmap = new WorkingBeatmap(new Beatmap
|
||||
{
|
||||
Beatmap = new Beatmap
|
||||
{
|
||||
HitObjects = objects
|
||||
}
|
||||
}
|
||||
HitObjects = objects
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -12,9 +12,12 @@ namespace osu.Game.Beatmaps
|
||||
{
|
||||
public class WorkingBeatmap : IDisposable
|
||||
{
|
||||
public BeatmapInfo BeatmapInfo;
|
||||
public readonly BeatmapInfo BeatmapInfo;
|
||||
|
||||
public readonly ArchiveReader Reader;
|
||||
public readonly BeatmapSetInfo BeatmapSetInfo;
|
||||
private readonly BeatmapDatabase database;
|
||||
|
||||
private ArchiveReader reader => database.GetReader(BeatmapSetInfo);
|
||||
|
||||
private Beatmap beatmap;
|
||||
public Beatmap Beatmap
|
||||
@ -25,7 +28,7 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
try
|
||||
{
|
||||
using (var stream = new StreamReader(Reader.ReadFile(BeatmapInfo.Path)))
|
||||
using (var stream = new StreamReader(reader.ReadFile(BeatmapInfo.Path)))
|
||||
beatmap = BeatmapDecoder.GetDecoder(stream)?.Decode(stream);
|
||||
}
|
||||
catch { }
|
||||
@ -44,7 +47,7 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
try
|
||||
{
|
||||
var trackData = Reader.ReadFile(BeatmapInfo.Metadata.AudioFile);
|
||||
var trackData = reader.ReadFile(BeatmapInfo.Metadata.AudioFile);
|
||||
if (trackData != null)
|
||||
track = new AudioTrackBass(trackData);
|
||||
}
|
||||
@ -55,10 +58,16 @@ namespace osu.Game.Beatmaps
|
||||
set { track = value; }
|
||||
}
|
||||
|
||||
public WorkingBeatmap(BeatmapInfo beatmapInfo = null, ArchiveReader reader = null)
|
||||
public WorkingBeatmap(Beatmap beatmap)
|
||||
{
|
||||
this.beatmap = beatmap;
|
||||
}
|
||||
|
||||
public WorkingBeatmap(BeatmapInfo beatmapInfo, BeatmapSetInfo beatmapSetInfo, BeatmapDatabase database)
|
||||
{
|
||||
this.BeatmapInfo = beatmapInfo;
|
||||
Reader = reader;
|
||||
this.BeatmapSetInfo = beatmapSetInfo;
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
private bool isDisposed;
|
||||
@ -68,7 +77,7 @@ namespace osu.Game.Beatmaps
|
||||
if (!isDisposed)
|
||||
{
|
||||
track?.Dispose();
|
||||
Reader?.Dispose();
|
||||
reader?.Dispose();
|
||||
isDisposed = true;
|
||||
}
|
||||
}
|
||||
|
@ -149,12 +149,10 @@ namespace osu.Game.Database
|
||||
if (beatmapSetInfo == null)
|
||||
throw new InvalidOperationException($@"Beatmap set {beatmapInfo.BeatmapSetID} is not in the local database.");
|
||||
|
||||
var reader = GetReader(beatmapSetInfo);
|
||||
|
||||
if (beatmapInfo.Metadata == null)
|
||||
beatmapInfo.Metadata = beatmapSetInfo.Metadata;
|
||||
|
||||
var working = new WorkingBeatmap(beatmapInfo, reader);
|
||||
var working = new WorkingBeatmap(beatmapInfo, beatmapSetInfo, this);
|
||||
|
||||
previous?.TransferTo(working);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user