fix: Occasional crash when loading project files

This commit is contained in:
WerWolv
2023-04-06 12:44:25 +02:00
parent 1698f1599b
commit 5f713882d4
2 changed files with 17 additions and 5 deletions

View File

@@ -239,12 +239,13 @@ namespace hex {
}
void TaskManager::collectGarbage() {
std::unique_lock lock1(s_queueMutex);
std::unique_lock lock2(s_deferredCallsMutex);
std::erase_if(s_tasks, [](const auto &task) { return task->isFinished() && !task->hadException(); });
{
std::unique_lock lock1(s_queueMutex);
std::erase_if(s_tasks, [](const auto &task) { return task->isFinished() && !task->hadException(); });
}
if (s_tasks.empty()) {
std::unique_lock lock2(s_deferredCallsMutex);
for (auto &call : s_tasksFinishedCallbacks)
call();
s_tasksFinishedCallbacks.clear();