fix: Occasional crashes when evaluating patterns

This commit is contained in:
WerWolv
2023-06-21 10:30:00 +02:00
parent 6435d8d955
commit 9cd19063da
2 changed files with 16 additions and 18 deletions

View File

@@ -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<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 {

View File

@@ -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())) {