1
0
mirror of synced 2024-12-01 10:47:19 +01:00

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

@ -1 +1 @@
Subproject commit 337a45a7684e46ae2c7462f82097af428b7d52d3 Subproject commit 72ab71a9166063f4688bc87d55be08ead4f0c1d7

View File

@ -21,6 +21,7 @@ namespace hex::plugin::builtin {
private: private:
ui::PatternDrawer m_patternDrawer; ui::PatternDrawer m_patternDrawer;
bool m_shouldReset = false; bool m_shouldReset = false;
u64 m_lastRunId = 0;
}; };
} }

View File

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