diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index c86860f7b0..7d1aaedfed 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -101,15 +101,26 @@ namespace osu.Game.Beatmaps /// public Func GetStableStorage { private get; set; } + private void refreshImportContext() + { + lock (importContextLock) + { + importContext?.Value?.Dispose(); + + importContext = new Lazy(() => + { + var c = createContext(); + c.Database.AutoTransactionsEnabled = false; + return c; + }); + } + } + public BeatmapManager(Storage storage, Func context, RulesetStore rulesets, APIAccess api, IIpcHost importHost = null) { createContext = context; - importContext = new Lazy(() => - { - var c = createContext(); - c.Database.AutoTransactionsEnabled = false; - return c; - }); + + refreshImportContext(); beatmaps = createBeatmapStore(context); files = new FileStore(context, storage); @@ -174,13 +185,16 @@ namespace osu.Game.Beatmaps { e = e.InnerException ?? e; Logger.Error(e, $@"Could not import beatmap set ({Path.GetFileName(path)})"); + refreshImportContext(); } } notification.State = ProgressNotificationState.Completed; } - private readonly Lazy importContext; + private readonly object importContextLock = new object(); + + private Lazy importContext; /// /// Import a beatmap from an . @@ -189,7 +203,7 @@ namespace osu.Game.Beatmaps public BeatmapSetInfo Import(ArchiveReader archiveReader) { // let's only allow one concurrent import at a time for now. - lock (importContext) + lock (importContextLock) { var context = importContext.Value; @@ -314,7 +328,7 @@ namespace osu.Game.Beatmaps /// The beatmap set to delete. public void Delete(BeatmapSetInfo beatmapSet) { - lock (importContext) + lock (importContextLock) { var context = importContext.Value; @@ -377,7 +391,7 @@ namespace osu.Game.Beatmaps if (beatmapSet.Protected) return; - lock (importContext) + lock (importContextLock) { var context = importContext.Value;