1
0
mirror of synced 2024-11-24 07:40:17 +01:00

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

@ -1 +1 @@
Subproject commit 8d78e153d9ee628a8fe80019effcdd2f7785224f
Subproject commit a94d3e7189f3dd7e5f9107b27e52924f047570f3

View File

@ -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);

View File

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

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;