mirror of
https://github.com/ppy/osu
synced 2025-02-01 10:51:53 +00:00
Merge pull request #11820 from smoogipoo/fix-offthread-collection-import
Fix collections being imported from BDL thread
This commit is contained in:
commit
cea9ecc2cc
@ -139,22 +139,19 @@ namespace osu.Game.Collections
|
|||||||
PostNotification?.Invoke(notification);
|
PostNotification?.Invoke(notification);
|
||||||
|
|
||||||
var collection = readCollections(stream, notification);
|
var collection = readCollections(stream, notification);
|
||||||
bool importCompleted = false;
|
await importCollections(collection);
|
||||||
|
|
||||||
Schedule(() =>
|
|
||||||
{
|
|
||||||
importCollections(collection);
|
|
||||||
importCompleted = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
while (!IsDisposed && !importCompleted)
|
|
||||||
await Task.Delay(10);
|
|
||||||
|
|
||||||
notification.CompletionText = $"Imported {collection.Count} collections";
|
notification.CompletionText = $"Imported {collection.Count} collections";
|
||||||
notification.State = ProgressNotificationState.Completed;
|
notification.State = ProgressNotificationState.Completed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void importCollections(List<BeatmapCollection> newCollections)
|
private Task importCollections(List<BeatmapCollection> newCollections)
|
||||||
|
{
|
||||||
|
var tcs = new TaskCompletionSource<bool>();
|
||||||
|
|
||||||
|
Schedule(() =>
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
foreach (var newCol in newCollections)
|
foreach (var newCol in newCollections)
|
||||||
{
|
{
|
||||||
@ -168,6 +165,17 @@ namespace osu.Game.Collections
|
|||||||
existing.Beatmaps.Add(newBeatmap);
|
existing.Beatmaps.Add(newBeatmap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tcs.SetResult(true);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logger.Error(e, "Failed to import collection.");
|
||||||
|
tcs.SetException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return tcs.Task;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<BeatmapCollection> readCollections(Stream stream, ProgressNotification notification = null)
|
private List<BeatmapCollection> readCollections(Stream stream, ProgressNotification notification = null)
|
||||||
|
Loading…
Reference in New Issue
Block a user