fix: Handling of exceptions that are not being caught

This commit is contained in:
WerWolv
2022-10-03 10:36:19 +02:00
parent accd554600
commit b17cd3696c
6 changed files with 46 additions and 39 deletions

View File

@@ -18,6 +18,7 @@ namespace hex::plugin::builtin {
struct {
std::string sourceCode;
std::unique_ptr<pl::PatternLanguage> runtime;
bool executionDone = true;
} patternLanguage;
std::list<ImHexApi::Bookmarks::Entry> bookmarks;

View File

@@ -108,9 +108,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 provider = ImHexApi::Provider::get();
auto &runtime = ProviderExtraData::get(provider).patternLanguage.runtime;
auto &patternLanguage = ProviderExtraData::get(provider).patternLanguage;
if (provider->isReadable() && runtime != nullptr && !runtime->isRunning()) {
if (provider->isReadable() && patternLanguage.runtime != nullptr && patternLanguage.executionDone) {
auto &sortedPatterns = this->m_sortedPatterns[ImHexApi::Provider::get()];
if (beginPatternTable(provider, ProviderExtraData::get(provider).patternLanguage.runtime->getAllPatterns(), sortedPatterns)) {
ImGui::TableHeadersRow();

View File

@@ -445,30 +445,31 @@ namespace hex::plugin::builtin {
}
View::discardNavigationRequests();
if (!this->m_lastEvaluationProcessed) {
this->m_console = this->m_lastEvaluationLog;
if (!this->m_lastEvaluationResult) {
if (this->m_lastEvaluationError) {
TextEditor::ErrorMarkers errorMarkers = {
{ this->m_lastEvaluationError->line, this->m_lastEvaluationError->message }
};
this->m_textEditor.SetErrorMarkers(errorMarkers);
}
} else {
for (auto &[name, variable] : this->m_patternVariables) {
if (variable.outVariable && this->m_lastEvaluationOutVars.contains(name))
variable.value = this->m_lastEvaluationOutVars.at(name);
}
EventManager::post<EventHighlightingChanged>();
}
this->m_lastEvaluationProcessed = true;
ProviderExtraData::get(provider).patternLanguage.executionDone = true;
}
}
ImGui::End();
if (!this->m_lastEvaluationProcessed) {
this->m_console = this->m_lastEvaluationLog;
if (!this->m_lastEvaluationResult) {
if (this->m_lastEvaluationError) {
TextEditor::ErrorMarkers errorMarkers = {
{ this->m_lastEvaluationError->line, this->m_lastEvaluationError->message }
};
this->m_textEditor.SetErrorMarkers(errorMarkers);
}
} else {
for (auto &[name, variable] : this->m_patternVariables) {
if (variable.outVariable && this->m_lastEvaluationOutVars.contains(name))
variable.value = this->m_lastEvaluationOutVars.at(name);
}
EventManager::post<EventHighlightingChanged>();
}
this->m_lastEvaluationProcessed = true;
}
}
void ViewPatternEditor::drawConsole(ImVec2 size) {
@@ -814,19 +815,23 @@ namespace hex::plugin::builtin {
}
void ViewPatternEditor::evaluatePattern(const std::string &code) {
auto provider = ImHexApi::Provider::get();
auto &patternLanguage = ProviderExtraData::get(provider).patternLanguage;
this->m_runningEvaluators++;
patternLanguage.executionDone = false;
this->m_textEditor.SetErrorMarkers({});
this->m_console.clear();
auto provider = ImHexApi::Provider::get();
auto &runtime = ProviderExtraData::get(provider).patternLanguage.runtime;
ContentRegistry::PatternLanguage::configureRuntime(*runtime, provider);
ContentRegistry::PatternLanguage::configureRuntime(*patternLanguage.runtime, provider);
EventManager::post<EventHighlightingChanged>();
TaskManager::createTask("hex.builtin.view.pattern_editor.evaluating", TaskManager::NoProgress, [this, &runtime, code](auto &task) {
TaskManager::createTask("hex.builtin.view.pattern_editor.evaluating", TaskManager::NoProgress, [this, &patternLanguage, code](auto &task) {
auto &runtime = patternLanguage.runtime;
task.setInterruptCallback([&runtime] { runtime->abort(); });
std::map<std::string, pl::core::Token::Literal> envVars;