diff --git a/lib/libimhex/include/hex/api/task.hpp b/lib/libimhex/include/hex/api/task.hpp index c4729789f..93820a196 100644 --- a/lib/libimhex/include/hex/api/task.hpp +++ b/lib/libimhex/include/hex/api/task.hpp @@ -29,7 +29,6 @@ namespace hex { void update(u64 value = 0); void setMaxValue(u64 value); - [[nodiscard]] bool isRunning() const; [[nodiscard]] bool isBackgroundTask() const; [[nodiscard]] bool isFinished() const; [[nodiscard]] bool hadException() const; @@ -45,8 +44,6 @@ namespace hex { void setInterruptCallback(std::function callback); - void setRunning(bool running); - private: void finish(); void interruption(); @@ -60,7 +57,6 @@ namespace hex { std::function m_interruptCallback; std::function m_function; - std::atomic m_running = false; std::atomic m_shouldInterrupt = false; std::atomic m_background = true; diff --git a/lib/libimhex/source/api/task.cpp b/lib/libimhex/source/api/task.cpp index 7f45219b9..f76373ecd 100644 --- a/lib/libimhex/source/api/task.cpp +++ b/lib/libimhex/source/api/task.cpp @@ -36,7 +36,6 @@ namespace hex { this->m_hadException = bool(other.m_hadException); this->m_interrupted = bool(other.m_interrupted); this->m_shouldInterrupt = bool(other.m_shouldInterrupt); - this->m_running = bool(other.m_running); } Task::~Task() { @@ -67,10 +66,6 @@ namespace hex { this->m_interruptCallback = std::move(callback); } - void Task::setRunning(bool running) { - this->m_running = running; - } - bool Task::isBackgroundTask() const { return this->m_background; } @@ -91,10 +86,6 @@ namespace hex { this->m_hadException = false; } - bool Task::isRunning() const { - return this->m_running; - } - std::string Task::getExceptionMessage() const { std::scoped_lock lock(this->m_mutex); @@ -130,20 +121,35 @@ namespace hex { bool TaskHolder::isRunning() const { - return !m_task.expired() && !m_task.lock()->isFinished(); + if (this->m_task.expired()) + return false; + + auto task = this->m_task.lock(); + return !task->isFinished(); } bool TaskHolder::hadException() const { - return m_task.expired() || m_task.lock()->hadException(); + if (this->m_task.expired()) + return false; + + auto task = this->m_task.lock(); + return !task->hadException(); } bool TaskHolder::wasInterrupted() const { - return m_task.expired() || m_task.lock()->wasInterrupted(); + if (this->m_task.expired()) + return false; + + auto task = this->m_task.lock(); + return !task->wasInterrupted(); } void TaskHolder::interrupt() { - if (!this->m_task.expired()) - this->m_task.lock()->interrupt(); + if (this->m_task.expired()) + return; + + auto task = this->m_task.lock(); + task->interrupt(); } @@ -176,7 +182,7 @@ namespace hex { if (stopToken.stop_requested()) break; - task = s_tasks.front(); + task = std::move(s_tasks.front()); s_tasks.pop_front(); } diff --git a/main/source/main.cpp b/main/source/main.cpp index e6e1249b1..ac8fbdcf6 100644 --- a/main/source/main.cpp +++ b/main/source/main.cpp @@ -63,10 +63,10 @@ int main(int argc, char **argv, char **envp) { window.loop(); } catch (const std::exception &e) { log::fatal("Exception thrown in main loop: {}", e.what()); - return EXIT_FAILURE; + throw; } catch (...) { log::fatal("Unknown exception thrown in main loop!"); - return EXIT_FAILURE; + throw; } } diff --git a/plugins/builtin/source/content/views/view_data_inspector.cpp b/plugins/builtin/source/content/views/view_data_inspector.cpp index 15b63d125..08c150081 100644 --- a/plugins/builtin/source/content/views/view_data_inspector.cpp +++ b/plugins/builtin/source/content/views/view_data_inspector.cpp @@ -37,6 +37,11 @@ namespace hex::plugin::builtin { } void ViewDataInspector::drawContent() { + if (this->m_dataValid) { + this->m_dataValid = false; + this->m_cachedData = std::move(this->m_workData); + } + if (this->m_shouldInvalidate && !this->m_updateTask.isRunning()) { this->m_shouldInvalidate = false; @@ -133,11 +138,6 @@ namespace hex::plugin::builtin { }); } - if (this->m_dataValid) { - this->m_dataValid = false; - this->m_cachedData = this->m_workData; - } - if (ImGui::Begin(View::toWindowName("hex.builtin.view.data_inspector.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) { auto provider = ImHexApi::Provider::get();