diff --git a/lib/libimhex/source/api/task_manager.cpp b/lib/libimhex/source/api/task_manager.cpp index 8e4599279..f4d8e522d 100644 --- a/lib/libimhex/source/api/task_manager.cpp +++ b/lib/libimhex/source/api/task_manager.cpp @@ -194,6 +194,10 @@ namespace hex { // Store information about the caught exception m_exceptionMessage = message; m_hadException = true; + + // Call the interrupt callback on the current thread if one is set + if (m_interruptCallback) + m_interruptCallback(); } diff --git a/plugins/diffing/include/content/views/view_diff.hpp b/plugins/diffing/include/content/views/view_diff.hpp index 5ea6372ac..9fa9f1f19 100644 --- a/plugins/diffing/include/content/views/view_diff.hpp +++ b/plugins/diffing/include/content/views/view_diff.hpp @@ -42,6 +42,7 @@ namespace hex::plugin::diffing { TaskHolder m_diffTask; std::atomic m_analyzed = false; + std::atomic m_analysisInterrupted = false; ContentRegistry::Diffing::Algorithm *m_algorithm = nullptr; }; diff --git a/plugins/diffing/source/content/views/view_diff.cpp b/plugins/diffing/source/content/views/view_diff.cpp index 85ac27600..1b8a9b05c 100644 --- a/plugins/diffing/source/content/views/view_diff.cpp +++ b/plugins/diffing/source/content/views/view_diff.cpp @@ -19,7 +19,7 @@ namespace hex::plugin::diffing { this->reset(); }); EventDataChanged::subscribe(this, [this](prv::Provider *) { - m_analyzed = false; + m_analysisInterrupted = m_analyzed = false; }); // Set the background highlight callbacks for the two hex editor columns @@ -94,7 +94,9 @@ namespace hex::plugin::diffing { void ViewDiff::analyze(prv::Provider *providerA, prv::Provider *providerB) { auto commonSize = std::max(providerA->getActualSize(), providerB->getActualSize()); - m_diffTask = TaskManager::createTask("hex.diffing.view.diff.task.diffing", commonSize, [this, providerA, providerB](Task &) { + m_diffTask = TaskManager::createTask("hex.diffing.view.diff.task.diffing", commonSize, [this, providerA, providerB](Task &task) { + task.setInterruptCallback([this]{ m_analysisInterrupted = true; }); + auto differences = m_algorithm->analyze(providerA, providerB); auto providers = ImHexApi::Provider::getProviders(); @@ -189,7 +191,7 @@ namespace hex::plugin::diffing { } // Analyze the providers if they are valid and the user selected a new provider - if (!m_analyzed && a.provider != -1 && b.provider != -1 && !m_diffTask.isRunning() && m_algorithm != nullptr) { + if (!m_analyzed && !m_analysisInterrupted && a.provider != -1 && b.provider != -1 && !m_diffTask.isRunning() && m_algorithm != nullptr) { const auto &providers = ImHexApi::Provider::getProviders(); auto providerA = providers[a.provider]; auto providerB = providers[b.provider]; @@ -229,11 +231,11 @@ namespace hex::plugin::diffing { ImGui::SameLine(); // Draw first provider selector - if (drawProviderSelector(a)) m_analyzed = false; + if (drawProviderSelector(a)) m_analysisInterrupted = m_analyzed = false; // Draw second provider selector ImGui::TableNextColumn(); - if (drawProviderSelector(b)) m_analyzed = false; + if (drawProviderSelector(b)) m_analysisInterrupted = m_analyzed = false; } ImGui::EndDisabled(); @@ -405,7 +407,7 @@ namespace hex::plugin::diffing { ImGui::PushID(algorithm.get()); if (ImGui::Selectable(Lang(algorithm->getUnlocalizedName()))) { m_algorithm = algorithm.get(); - m_analyzed = false; + m_analysisInterrupted = m_analyzed = false; } ImGui::PopID(); }