From fc8597c1a3980d3160e04ab65acabb76b0b7376a Mon Sep 17 00:00:00 2001 From: Christian Heinemann Date: Mon, 30 Sep 2024 23:33:25 +0200 Subject: [PATCH] show critical errors on screen --- source/Gui/AutosaveWindow.cpp | 2 +- source/Gui/MainWindow.cpp | 12 ++++++- .../PersisterImpl/PersisterControllerImpl.cpp | 9 +++-- .../PersisterImpl/PersisterControllerImpl.h | 4 +-- source/PersisterImpl/PersisterJob.cpp | 14 +++++--- source/PersisterImpl/PersisterJob.h | 12 ++++--- source/PersisterImpl/PersisterJobError.cpp | 11 ++++-- source/PersisterImpl/PersisterJobError.h | 4 ++- source/PersisterImpl/PersisterWorker.cpp | 35 ++++++++++++++----- source/PersisterImpl/PersisterWorker.h | 3 +- .../PersisterInterface/PersisterController.h | 4 +-- 11 files changed, 78 insertions(+), 32 deletions(-) diff --git a/source/Gui/AutosaveWindow.cpp b/source/Gui/AutosaveWindow.cpp index ec3e9d159..d8303af22 100644 --- a/source/Gui/AutosaveWindow.cpp +++ b/source/Gui/AutosaveWindow.cpp @@ -181,7 +181,7 @@ void _AutosaveWindow::createSavepoint() { printOverlayMessage("Creating save point ..."); static int i = 0; - auto jobId = _persisterController->scheduleSaveSimulationToDisc("d:\\test" + std::to_string(++i) + ".sim", Viewport::getZoomFactor(), Viewport::getCenterInWorldPos()); + auto jobId = _persisterController->scheduleSaveSimulationToDisc("d:\\test" + std::to_string(++i) + ".sim", false, Viewport::getZoomFactor(), Viewport::getCenterInWorldPos()); _savePoints.emplace_front(SavepointState::InQueue, jobId, "", "", 0); } diff --git a/source/Gui/MainWindow.cpp b/source/Gui/MainWindow.cpp index 385f3a87d..a515dd705 100644 --- a/source/Gui/MainWindow.cpp +++ b/source/Gui/MainWindow.cpp @@ -2,6 +2,8 @@ #include +#include + #include #include @@ -759,6 +761,14 @@ void _MainWindow::processControllers() _editorController->process(); OverlayMessageController::getInstance().process(); DelayedExecutionController::getInstance().process(); + auto criticalErrors = _persisterController->fetchCriticalErrorInfos(); + if (!criticalErrors.empty()) { + std::vector errorMessages; + for (auto const& error : criticalErrors) { + errorMessages.emplace_back(error.message); + } + MessageDialog::getInstance().information("Error", boost::join(errorMessages, "\n\n")); + } } void _MainWindow::onOpenSimulation() @@ -818,7 +828,7 @@ void _MainWindow::onSaveSimulation() auto firstFilenameCopy = firstFilename; _startingPath = firstFilenameCopy.remove_filename().string(); printOverlayMessage("Saving ..."); - _persisterController->scheduleSaveSimulationToDisc(firstFilename.string(), Viewport::getZoomFactor(), Viewport::getCenterInWorldPos()); + _persisterController->scheduleSaveSimulationToDisc(firstFilename.string(), true, Viewport::getZoomFactor(), Viewport::getCenterInWorldPos()); }); } diff --git a/source/PersisterImpl/PersisterControllerImpl.cpp b/source/PersisterImpl/PersisterControllerImpl.cpp index cb155c559..7c93f3ffc 100644 --- a/source/PersisterImpl/PersisterControllerImpl.cpp +++ b/source/PersisterImpl/PersisterControllerImpl.cpp @@ -40,16 +40,15 @@ PersisterJobState _PersisterControllerImpl::getJobState(PersisterJobId const& id return _worker->getJobState(id); } -std::vector _PersisterControllerImpl::fetchErrorInfos() +std::vector _PersisterControllerImpl::fetchCriticalErrorInfos() { - return {}; - //_worker->fetchErrorInfos(); + return _worker->fetchCriticalErrorInfos(); } -PersisterJobId _PersisterControllerImpl::scheduleSaveSimulationToDisc(std::string const& filename, float const& zoom, RealVector2D const& center) +PersisterJobId _PersisterControllerImpl::scheduleSaveSimulationToDisc(std::string const& filename, bool critical, float const& zoom, RealVector2D const& center) { auto jobId = generateNewJobId(); - auto saveToDiscJob = std::make_shared<_SaveToDiscJob>(jobId, filename, zoom, center); + auto saveToDiscJob = std::make_shared<_SaveToDiscJob>(jobId, critical, filename, zoom, center); _worker->addJob(saveToDiscJob); diff --git a/source/PersisterImpl/PersisterControllerImpl.h b/source/PersisterImpl/PersisterControllerImpl.h index acf4ce0ae..38793ab61 100644 --- a/source/PersisterImpl/PersisterControllerImpl.h +++ b/source/PersisterImpl/PersisterControllerImpl.h @@ -17,9 +17,9 @@ class _PersisterControllerImpl : public _PersisterController bool isBusy() const override; PersisterJobState getJobState(PersisterJobId const& id) const override; - std::vector fetchErrorInfos() override; + std::vector fetchCriticalErrorInfos() override; - PersisterJobId scheduleSaveSimulationToDisc(std::string const& filename, float const& zoom, RealVector2D const& center) override; + PersisterJobId scheduleSaveSimulationToDisc(std::string const& filename, bool critical, float const& zoom, RealVector2D const& center) override; std::variant fetchSavedSimulationData(PersisterJobId const& id) override; private: diff --git a/source/PersisterImpl/PersisterJob.cpp b/source/PersisterImpl/PersisterJob.cpp index f8122c6e8..d3413d764 100644 --- a/source/PersisterImpl/PersisterJob.cpp +++ b/source/PersisterImpl/PersisterJob.cpp @@ -1,16 +1,22 @@ #include "PersisterJob.h" -PersisterJobId _PersisterJob::getId() const +PersisterJobId const& _PersisterJob::getId() const { return _id; } -_PersisterJob::_PersisterJob(PersisterJobId const& id) +bool _PersisterJob::isCritical() const +{ + return _critical; +} + +_PersisterJob::_PersisterJob(PersisterJobId const& id, bool critical) : _id(id) + , _critical(critical) {} -_SaveToDiscJob::_SaveToDiscJob(PersisterJobId const& id, std::string const& filename, float const& zoom, RealVector2D const& center) - : _PersisterJob(id) +_SaveToDiscJob::_SaveToDiscJob(PersisterJobId const& id, bool critical, std::string const& filename, float const& zoom, RealVector2D const& center) + : _PersisterJob(id, critical) , _filename(filename) , _zoom(zoom) , _center(center) diff --git a/source/PersisterImpl/PersisterJob.h b/source/PersisterImpl/PersisterJob.h index 9926d9ab5..1272dd4cb 100644 --- a/source/PersisterImpl/PersisterJob.h +++ b/source/PersisterImpl/PersisterJob.h @@ -8,20 +8,22 @@ class _PersisterJob { public: - PersisterJobId getId() const; + PersisterJobId const& getId() const; + bool isCritical() const; protected: - _PersisterJob(PersisterJobId const& id); + _PersisterJob(PersisterJobId const& id, bool critical); virtual ~_PersisterJob() = default; - PersisterJobId _id = 0; + PersisterJobId _id; + bool _critical = true; }; using PersisterJob = std::shared_ptr<_PersisterJob>; class _SaveToDiscJob : public _PersisterJob { public: - _SaveToDiscJob(PersisterJobId const& id, std::string const& filename, float const& zoom, RealVector2D const& center); + _SaveToDiscJob(PersisterJobId const& id, bool critical, std::string const& filename, float const& zoom, RealVector2D const& center); std::string const& getFilename() const; float const& getZoom() const; @@ -29,7 +31,7 @@ class _SaveToDiscJob : public _PersisterJob private: std::string _filename; - float _zoom; + float _zoom = 0; RealVector2D _center; }; using SaveToDiscJob = std::shared_ptr<_SaveToDiscJob>; diff --git a/source/PersisterImpl/PersisterJobError.cpp b/source/PersisterImpl/PersisterJobError.cpp index 4a5f60308..55c81015f 100644 --- a/source/PersisterImpl/PersisterJobError.cpp +++ b/source/PersisterImpl/PersisterJobError.cpp @@ -1,7 +1,9 @@ #include "PersisterJobError.h" -_PersisterJobError::_PersisterJobError(PersisterJobId const& id, PersisterErrorInfo const& errorInfo) - : _id(id), _errorInfo(errorInfo) +_PersisterJobError::_PersisterJobError(PersisterJobId const& id, bool critical, PersisterErrorInfo const& errorInfo) + : _id(id) + , _critical(critical) + , _errorInfo(errorInfo) { } @@ -10,6 +12,11 @@ PersisterJobId const& _PersisterJobError::getId() const return _id; } +bool _PersisterJobError::isCritical() const +{ + return _critical; +} + PersisterErrorInfo const& _PersisterJobError::getErrorInfo() const { return _errorInfo; diff --git a/source/PersisterImpl/PersisterJobError.h b/source/PersisterImpl/PersisterJobError.h index 9cf2ea127..2df9ddcf4 100644 --- a/source/PersisterImpl/PersisterJobError.h +++ b/source/PersisterImpl/PersisterJobError.h @@ -5,14 +5,16 @@ class _PersisterJobError { public: - _PersisterJobError(PersisterJobId const& id, PersisterErrorInfo const& errorInfo); + _PersisterJobError(PersisterJobId const& id, bool critical, PersisterErrorInfo const& errorInfo); virtual ~_PersisterJobError() = default; PersisterJobId const& getId() const; + bool isCritical() const; PersisterErrorInfo const& getErrorInfo() const; protected: PersisterJobId _id; + bool _critical = true; PersisterErrorInfo _errorInfo; }; using PersisterJobError = std::shared_ptr<_PersisterJobError>; diff --git a/source/PersisterImpl/PersisterWorker.cpp b/source/PersisterImpl/PersisterWorker.cpp index 29051659b..433be23e0 100644 --- a/source/PersisterImpl/PersisterWorker.cpp +++ b/source/PersisterImpl/PersisterWorker.cpp @@ -55,6 +55,16 @@ PersisterJobState _PersisterWorker::getJobState(PersisterJobId const& id) const THROW_NOT_IMPLEMENTED(); } +void _PersisterWorker::addJob(PersisterJob const& job) +{ + { + std::unique_lock uniqueLock(_jobMutex); + + _openJobs.emplace_back(job); + } + _conditionVariable.notify_all(); +} + std::variant _PersisterWorker::fetchJobResult(PersisterJobId const& id) { std::unique_lock uniqueLock(_jobMutex); @@ -75,14 +85,21 @@ std::variant _PersisterWorker::fetchJobRe THROW_NOT_IMPLEMENTED(); } -void _PersisterWorker::addJob(PersisterJob const& job) +std::vector _PersisterWorker::fetchCriticalErrorInfos() { - { - std::unique_lock uniqueLock(_jobMutex); - - _openJobs.emplace_back(job); + std::unique_lock lock(_jobMutex); + + std::vector result; + std::deque filteredErrorJobs; + for (auto const& errorJob : _errorJobs) { + if (errorJob->isCritical()) { + result.emplace_back(errorJob->getErrorInfo()); + } else { + filteredErrorJobs.emplace_back(errorJob); + } } - _conditionVariable.notify_all(); + _errorJobs = filteredErrorJobs; + return result; } void _PersisterWorker::processJobs(std::unique_lock& lock) @@ -142,14 +159,16 @@ std::variant _PersisterWorker::processSav deserializedData.mainData = _simController->getClusteredSimulationData(); } catch (std::runtime_error const&) { return std::make_shared<_PersisterJobError>( - job->getId(), PersisterErrorInfo{"The simulation could not be saved because no valid data could be obtained from the GPU."}); + job->getId(), job->isCritical(), PersisterErrorInfo{"The simulation could not be saved because no valid data could be obtained from the GPU."}); } try { SerializerService::serializeSimulationToFiles(job->getFilename(), deserializedData); } catch (std::runtime_error const&) { return std::make_shared<_PersisterJobError>( - job->getId(), PersisterErrorInfo{"The simulation could not be saved because an error occurred when serializing the data to the file."}); + job->getId(), + job->isCritical(), + PersisterErrorInfo{"The simulation could not be saved because an error occurred when serializing the data to the file."}); } return std::make_shared<_SaveToDiscJobResult>(job->getId(), deserializedData.auxiliaryData.timestep, deserializedData.auxiliaryData.realTime); diff --git a/source/PersisterImpl/PersisterWorker.h b/source/PersisterImpl/PersisterWorker.h index a68f90db9..58d387233 100644 --- a/source/PersisterImpl/PersisterWorker.h +++ b/source/PersisterImpl/PersisterWorker.h @@ -22,9 +22,10 @@ class _PersisterWorker bool isBusy() const; PersisterJobState getJobState(PersisterJobId const& id) const; - std::variant fetchJobResult(PersisterJobId const& id); void addJob(PersisterJob const& job); + std::variant fetchJobResult(PersisterJobId const& id); + std::vector fetchCriticalErrorInfos(); private: void processJobs(std::unique_lock& lock); diff --git a/source/PersisterInterface/PersisterController.h b/source/PersisterInterface/PersisterController.h index 81430786b..5106143ca 100644 --- a/source/PersisterInterface/PersisterController.h +++ b/source/PersisterInterface/PersisterController.h @@ -19,9 +19,9 @@ class _PersisterController virtual bool isBusy() const = 0; virtual PersisterJobState getJobState(PersisterJobId const& id) const = 0; - virtual std::vector fetchErrorInfos() = 0; + virtual std::vector fetchCriticalErrorInfos() = 0; - virtual PersisterJobId scheduleSaveSimulationToDisc(std::string const& filename, float const& zoom, RealVector2D const& center) = 0; + virtual PersisterJobId scheduleSaveSimulationToDisc(std::string const& filename, bool critical, float const& zoom, RealVector2D const& center) = 0; struct SavedSimulationData { std::string name;