patterns: Fixed race condition when evaluating patterns

This commit is contained in:
WerWolv
2023-06-30 00:11:26 +02:00
parent 78cb0a2592
commit 4f08ba3590
3 changed files with 6 additions and 6 deletions

View File

@@ -20,10 +20,6 @@ namespace hex::plugin::builtin {
});
this->m_patternDrawer.setSelectionCallback([](Region region){ ImHexApi::HexEditor::setSelection(region); });
EventManager::subscribe<EventPatternExecuted>([this](const auto&){
this->m_shouldReset = true;
});
}
ViewPatternData::~ViewPatternData() {
@@ -36,11 +32,14 @@ namespace hex::plugin::builtin {
if (ImHexApi::Provider::isValid()) {
auto &runtime = ContentRegistry::PatternLanguage::getRuntime();
if (!runtime.arePatternsValid()) {
this->m_shouldReset = true;
this->m_patternDrawer.reset();
this->m_patternDrawer.draw({});
} else {
if (TRY_LOCK(ContentRegistry::PatternLanguage::getRuntimeLock())) {
if (this->m_shouldReset) {
auto runId = runtime.getRunId();
if (this->m_shouldReset || this->m_lastRunId != runId) {
this->m_lastRunId = runId;
this->m_patternDrawer.reset();
this->m_shouldReset = false;
}