mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 02:32:55 +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
|
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 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;
|
private Beatmap beatmap;
|
||||||
public Beatmap Beatmap
|
public Beatmap Beatmap
|
||||||
@ -25,7 +28,7 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
try
|
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);
|
beatmap = BeatmapDecoder.GetDecoder(stream)?.Decode(stream);
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
@ -44,7 +47,7 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var trackData = Reader.ReadFile(BeatmapInfo.Metadata.AudioFile);
|
var trackData = reader.ReadFile(BeatmapInfo.Metadata.AudioFile);
|
||||||
if (trackData != null)
|
if (trackData != null)
|
||||||
track = new AudioTrackBass(trackData);
|
track = new AudioTrackBass(trackData);
|
||||||
}
|
}
|
||||||
@ -55,10 +58,16 @@ namespace osu.Game.Beatmaps
|
|||||||
set { track = value; }
|
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;
|
this.BeatmapInfo = beatmapInfo;
|
||||||
Reader = reader;
|
this.BeatmapSetInfo = beatmapSetInfo;
|
||||||
|
this.database = database;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool isDisposed;
|
private bool isDisposed;
|
||||||
@ -68,7 +77,7 @@ namespace osu.Game.Beatmaps
|
|||||||
if (!isDisposed)
|
if (!isDisposed)
|
||||||
{
|
{
|
||||||
track?.Dispose();
|
track?.Dispose();
|
||||||
Reader?.Dispose();
|
reader?.Dispose();
|
||||||
isDisposed = true;
|
isDisposed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,12 +149,10 @@ namespace osu.Game.Database
|
|||||||
if (beatmapSetInfo == null)
|
if (beatmapSetInfo == null)
|
||||||
throw new InvalidOperationException($@"Beatmap set {beatmapInfo.BeatmapSetID} is not in the local database.");
|
throw new InvalidOperationException($@"Beatmap set {beatmapInfo.BeatmapSetID} is not in the local database.");
|
||||||
|
|
||||||
var reader = GetReader(beatmapSetInfo);
|
|
||||||
|
|
||||||
if (beatmapInfo.Metadata == null)
|
if (beatmapInfo.Metadata == null)
|
||||||
beatmapInfo.Metadata = beatmapSetInfo.Metadata;
|
beatmapInfo.Metadata = beatmapSetInfo.Metadata;
|
||||||
|
|
||||||
var working = new WorkingBeatmap(beatmapInfo, reader);
|
var working = new WorkingBeatmap(beatmapInfo, beatmapSetInfo, this);
|
||||||
|
|
||||||
previous?.TransferTo(working);
|
previous?.TransferTo(working);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user