1
0
mirror of synced 2024-09-24 19:48:25 +02:00

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(); });
}
if (s_tasks.empty()) {
std::unique_lock lock2(s_deferredCallsMutex);
for (auto &call : s_tasksFinishedCallbacks)
call();
s_tasksFinishedCallbacks.clear();

View File

@ -41,7 +41,18 @@ namespace hex::plugin::builtin {
auto providerSettings = nlohmann::json::parse(tar.readString(basePath / hex::format("{}.json", id)));
auto provider = ImHexApi::Provider::createProvider(providerSettings["type"].get<std::string>(), true);
ON_SCOPE_EXIT { if (!success) ImHexApi::Provider::remove(provider, true); };
ON_SCOPE_EXIT {
if (!success) {
for (auto &task : TaskManager::getRunningTasks())
task->interrupt();
TaskManager::runWhenTasksFinished([]{
for (auto provider : ImHexApi::Provider::getProviders())
ImHexApi::Provider::remove(provider, true);
});
}
};
if (provider == nullptr) {
success = false;
continue;