From 9cd19063dae16da379c9cb30866317e550743dbd Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 21 Jun 2023 10:30:00 +0200 Subject: [PATCH] fix: Occasional crashes when evaluating patterns --- .../source/content/data_processor_nodes.cpp | 33 +++++++++---------- .../content/views/view_pattern_data.cpp | 1 + 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/plugins/builtin/source/content/data_processor_nodes.cpp b/plugins/builtin/source/content/data_processor_nodes.cpp index a461968ce..7779a8db5 100644 --- a/plugins/builtin/source/content/data_processor_nodes.cpp +++ b/plugins/builtin/source/content/data_processor_nodes.cpp @@ -1165,28 +1165,25 @@ namespace hex::plugin::builtin { } void process() override { + auto lock = std::scoped_lock(ContentRegistry::PatternLanguage::getRuntimeLock()); auto &runtime = ContentRegistry::PatternLanguage::getRuntime(); - if (TRY_LOCK(ContentRegistry::PatternLanguage::getRuntimeLock())) { - const auto &outVars = runtime.getOutVariables(); - - if (outVars.contains(this->m_name)) { - std::visit(wolv::util::overloaded { - [](const std::string &) {}, - [](pl::ptrn::Pattern *) {}, - [this](auto &&value) { - std::vector buffer(std::min(sizeof(value), 8)); - std::memcpy(buffer.data(), &value, buffer.size()); - - this->setBufferOnOutput(0, buffer); - } - }, outVars.at(this->m_name)); - } else { - throwNodeError(hex::format("Out variable '{}' has not been defined!", this->m_name)); - } - } const auto &outVars = runtime.getOutVariables(); + if (outVars.contains(this->m_name)) { + std::visit(wolv::util::overloaded { + [](const std::string &) {}, + [](pl::ptrn::Pattern *) {}, + [this](auto &&value) { + std::vector buffer(std::min(sizeof(value), 8)); + std::memcpy(buffer.data(), &value, buffer.size()); + + this->setBufferOnOutput(0, buffer); + } + }, outVars.at(this->m_name)); + } else { + throwNodeError(hex::format("Out variable '{}' has not been defined!", this->m_name)); + } } void store(nlohmann::json &j) const override { diff --git a/plugins/builtin/source/content/views/view_pattern_data.cpp b/plugins/builtin/source/content/views/view_pattern_data.cpp index 72bcef65c..12192947f 100644 --- a/plugins/builtin/source/content/views/view_pattern_data.cpp +++ b/plugins/builtin/source/content/views/view_pattern_data.cpp @@ -36,6 +36,7 @@ namespace hex::plugin::builtin { if (ImHexApi::Provider::isValid()) { auto &runtime = ContentRegistry::PatternLanguage::getRuntime(); if (!runtime.arePatternsValid()) { + this->m_patternDrawer.reset(); this->m_patternDrawer.draw({}); } else { if (TRY_LOCK(ContentRegistry::PatternLanguage::getRuntimeLock())) {