fix: Handling of exceptions that are not being caught
This commit is contained in:
parent
accd554600
commit
b17cd3696c
2
lib/external/pattern_language
vendored
2
lib/external/pattern_language
vendored
@ -1 +1 @@
|
||||
Subproject commit 8d78e153d9ee628a8fe80019effcdd2f7785224f
|
||||
Subproject commit a94d3e7189f3dd7e5f9107b27e52924f047570f3
|
@ -57,7 +57,15 @@ int main(int argc, char **argv, char **envp) {
|
||||
EventManager::post<RequestOpenFile>(argv[i]);
|
||||
}
|
||||
|
||||
window.loop();
|
||||
try {
|
||||
window.loop();
|
||||
} catch (const std::exception &e) {
|
||||
log::fatal("Exception thrown in main loop: {}", e.what());
|
||||
return EXIT_FAILURE;
|
||||
} catch (...) {
|
||||
log::fatal("Unknown exception thrown in main loop!");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
} while (shouldRestart);
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <hex/helpers/utils.hpp>
|
||||
#include <hex/helpers/fs.hpp>
|
||||
#include <hex/helpers/logger.hpp>
|
||||
#include <fmt/printf.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <csignal>
|
||||
@ -200,15 +201,7 @@ namespace hex {
|
||||
}
|
||||
|
||||
this->frameBegin();
|
||||
|
||||
try {
|
||||
this->frame();
|
||||
} catch (const std::exception &e) {
|
||||
log::error("Exception thrown in main loop: {}", e.what());
|
||||
} catch (...) {
|
||||
log::error("Unknown exception thrown in main loop!");
|
||||
}
|
||||
|
||||
this->frame();
|
||||
this->frameEnd();
|
||||
|
||||
const auto targetFps = ImHexApi::System::getTargetFPS();
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user