diff --git a/lib/external/libwolv b/lib/external/libwolv index d02e65c13..7b441291c 160000 --- a/lib/external/libwolv +++ b/lib/external/libwolv @@ -1 +1 @@ -Subproject commit d02e65c1357b25327b6fe2d02f470788e9e537e6 +Subproject commit 7b441291cd8f13c5d15e104d46b82a3fc493adcf diff --git a/plugins/builtin/source/content/data_processor_nodes.cpp b/plugins/builtin/source/content/data_processor_nodes.cpp index 52f4269a7..349a04ebd 100644 --- a/plugins/builtin/source/content/data_processor_nodes.cpp +++ b/plugins/builtin/source/content/data_processor_nodes.cpp @@ -19,6 +19,7 @@ #include #include +#include namespace hex::plugin::builtin { @@ -1162,25 +1163,28 @@ 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 3878290cb..39a934a06 100644 --- a/plugins/builtin/source/content/views/view_pattern_data.cpp +++ b/plugins/builtin/source/content/views/view_pattern_data.cpp @@ -4,6 +4,7 @@ #include #include +#include namespace hex::plugin::builtin { @@ -34,11 +35,9 @@ namespace hex::plugin::builtin { if (ImGui::Begin(View::toWindowName("hex.builtin.view.pattern_data.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) { if (ImHexApi::Provider::isValid()) { auto &runtime = ContentRegistry::PatternLanguage::getRuntime(); - if (!runtime.arePatternsValid()) { + if (TRY_LOCK(ContentRegistry::PatternLanguage::getRuntimeLock()) || !runtime.arePatternsValid()) { this->m_patternDrawer.draw({}); } else { - auto lock = std::scoped_lock(ContentRegistry::PatternLanguage::getRuntimeLock()); - if (this->m_shouldReset) { this->m_patternDrawer.reset(); this->m_shouldReset = false; diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index 63cecd238..9702badfb 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -23,6 +23,7 @@ #include #include #include +#include namespace hex::plugin::builtin { @@ -142,7 +143,6 @@ namespace hex::plugin::builtin { ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1); { - auto lock = std::scoped_lock(ContentRegistry::PatternLanguage::getRuntimeLock()); auto &runtime = ContentRegistry::PatternLanguage::getRuntime(); if (runtime.isRunning()) { if (ImGui::IconButton(ICON_VS_DEBUG_STOP, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarRed))) @@ -649,6 +649,7 @@ namespace hex::plugin::builtin { this->m_runningEvaluators++; *this->m_executionDone = false; + this->m_textEditor.SetErrorMarkers({}); this->m_console->clear(); @@ -705,7 +706,7 @@ namespace hex::plugin::builtin { *this->m_lastEvaluationError = runtime.getError(); } - TaskManager::doLater([code = std::move(code)] { + TaskManager::doLater([code] { EventManager::post(code); }); }); @@ -942,18 +943,20 @@ namespace hex::plugin::builtin { if (this->m_runningEvaluators != 0) return std::nullopt; - auto lock = std::scoped_lock(ContentRegistry::PatternLanguage::getRuntimeLock()); auto &runtime = ContentRegistry::PatternLanguage::getRuntime(); std::optional color; - for (const auto &pattern : runtime.getPatternsAtAddress(address)) { - if (pattern->getVisibility() != pl::ptrn::Visibility::Visible) - continue; - if (color.has_value()) - color = ImAlphaBlendColors(*color, pattern->getColor()); - else - color = pattern->getColor(); + if (TRY_LOCK(ContentRegistry::PatternLanguage::getRuntimeLock())) { + for (const auto &pattern : runtime.getPatternsAtAddress(address)) { + if (pattern->getVisibility() != pl::ptrn::Visibility::Visible) + continue; + + if (color.has_value()) + color = ImAlphaBlendColors(*color, pattern->getColor()); + else + color = pattern->getColor(); + } } return color; @@ -962,33 +965,34 @@ namespace hex::plugin::builtin { ImHexApi::HexEditor::addTooltipProvider([this](u64 address, const u8 *data, size_t size) { hex::unused(data, size); - auto lock = std::scoped_lock(ContentRegistry::PatternLanguage::getRuntimeLock()); - auto &runtime = ContentRegistry::PatternLanguage::getRuntime(); + if (TRY_LOCK(ContentRegistry::PatternLanguage::getRuntimeLock())) { + auto &runtime = ContentRegistry::PatternLanguage::getRuntime(); - auto patterns = runtime.getPatternsAtAddress(address); - if (!patterns.empty() && !std::all_of(patterns.begin(), patterns.end(), [](const auto &pattern) { return pattern->getVisibility() == pl::ptrn::Visibility::Hidden; })) { - ImGui::BeginTooltip(); + auto patterns = runtime.getPatternsAtAddress(address); + if (!patterns.empty() && !std::all_of(patterns.begin(), patterns.end(), [](const auto &pattern) { return pattern->getVisibility() == pl::ptrn::Visibility::Hidden; })) { + ImGui::BeginTooltip(); - for (const auto &pattern : patterns) { - if (pattern->getVisibility() != pl::ptrn::Visibility::Visible) - continue; + for (const auto &pattern : patterns) { + if (pattern->getVisibility() != pl::ptrn::Visibility::Visible) + continue; - auto tooltipColor = (pattern->getColor() & 0x00FF'FFFF) | 0x7000'0000; - ImGui::PushID(pattern); - if (ImGui::BeginTable("##tooltips", 1, ImGuiTableFlags_RowBg | ImGuiTableFlags_NoClip)) { - ImGui::TableNextRow(); - ImGui::TableNextColumn(); + auto tooltipColor = (pattern->getColor() & 0x00FF'FFFF) | 0x7000'0000; + ImGui::PushID(pattern); + if (ImGui::BeginTable("##tooltips", 1, ImGuiTableFlags_RowBg | ImGuiTableFlags_NoClip)) { + ImGui::TableNextRow(); + ImGui::TableNextColumn(); - this->drawPatternTooltip(pattern); + this->drawPatternTooltip(pattern); - ImGui::PushStyleColor(ImGuiCol_TableRowBg, tooltipColor); - ImGui::PushStyleColor(ImGuiCol_TableRowBgAlt, tooltipColor); - ImGui::EndTable(); - ImGui::PopStyleColor(2); + ImGui::PushStyleColor(ImGuiCol_TableRowBg, tooltipColor); + ImGui::PushStyleColor(ImGuiCol_TableRowBgAlt, tooltipColor); + ImGui::EndTable(); + ImGui::PopStyleColor(2); + } + ImGui::PopID(); } - ImGui::PopID(); + ImGui::EndTooltip(); } - ImGui::EndTooltip(); } });