mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-30 13:05:25 -05:00
fix: ImHex freezing when evaluating patterns
This commit is contained in:
2
lib/external/libwolv
vendored
2
lib/external/libwolv
vendored
Submodule lib/external/libwolv updated: d02e65c135...7b441291cd
@@ -19,6 +19,7 @@
|
||||
#include <hex/ui/imgui_imhex_extensions.h>
|
||||
|
||||
#include <wolv/utils/core.hpp>
|
||||
#include <wolv/utils/lock.hpp>
|
||||
|
||||
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<u8> buffer(std::min<size_t>(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<u8> buffer(std::min<size_t>(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 {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <hex/providers/provider.hpp>
|
||||
|
||||
#include <pl/patterns/pattern.hpp>
|
||||
#include <wolv/utils/lock.hpp>
|
||||
|
||||
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;
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <wolv/io/file.hpp>
|
||||
#include <wolv/io/fs.hpp>
|
||||
#include <wolv/utils/guards.hpp>
|
||||
#include <wolv/utils/lock.hpp>
|
||||
|
||||
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<EventPatternExecuted>(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<ImColor> 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();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user