Skip to content

Commit

Permalink
show critical errors on screen
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Sep 30, 2024
1 parent 17cdfa2 commit fc8597c
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 32 deletions.
2 changes: 1 addition & 1 deletion source/Gui/AutosaveWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
12 changes: 11 additions & 1 deletion source/Gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <iostream>

#include <boost/algorithm/string.hpp>

#include <glad/glad.h>

#include <imgui.h>
Expand Down Expand Up @@ -759,6 +761,14 @@ void _MainWindow::processControllers()
_editorController->process();
OverlayMessageController::getInstance().process();
DelayedExecutionController::getInstance().process();
auto criticalErrors = _persisterController->fetchCriticalErrorInfos();
if (!criticalErrors.empty()) {
std::vector<std::string> errorMessages;
for (auto const& error : criticalErrors) {
errorMessages.emplace_back(error.message);
}
MessageDialog::getInstance().information("Error", boost::join(errorMessages, "\n\n"));
}
}

void _MainWindow::onOpenSimulation()
Expand Down Expand Up @@ -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());
});
}

Expand Down
9 changes: 4 additions & 5 deletions source/PersisterImpl/PersisterControllerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,15 @@ PersisterJobState _PersisterControllerImpl::getJobState(PersisterJobId const& id
return _worker->getJobState(id);
}

std::vector<PersisterErrorInfo> _PersisterControllerImpl::fetchErrorInfos()
std::vector<PersisterErrorInfo> _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);

Expand Down
4 changes: 2 additions & 2 deletions source/PersisterImpl/PersisterControllerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class _PersisterControllerImpl : public _PersisterController

bool isBusy() const override;
PersisterJobState getJobState(PersisterJobId const& id) const override;
std::vector<PersisterErrorInfo> fetchErrorInfos() override;
std::vector<PersisterErrorInfo> 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<SavedSimulationData, PersisterErrorInfo> fetchSavedSimulationData(PersisterJobId const& id) override;

private:
Expand Down
14 changes: 10 additions & 4 deletions source/PersisterImpl/PersisterJob.cpp
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
12 changes: 7 additions & 5 deletions source/PersisterImpl/PersisterJob.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,30 @@
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;
RealVector2D const& getCenter() const;

private:
std::string _filename;
float _zoom;
float _zoom = 0;
RealVector2D _center;
};
using SaveToDiscJob = std::shared_ptr<_SaveToDiscJob>;
11 changes: 9 additions & 2 deletions source/PersisterImpl/PersisterJobError.cpp
Original file line number Diff line number Diff line change
@@ -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)
{
}

Expand All @@ -10,6 +12,11 @@ PersisterJobId const& _PersisterJobError::getId() const
return _id;
}

bool _PersisterJobError::isCritical() const
{
return _critical;
}

PersisterErrorInfo const& _PersisterJobError::getErrorInfo() const
{
return _errorInfo;
Expand Down
4 changes: 3 additions & 1 deletion source/PersisterImpl/PersisterJobError.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
35 changes: 27 additions & 8 deletions source/PersisterImpl/PersisterWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<PersisterJobResult, PersisterJobError> _PersisterWorker::fetchJobResult(PersisterJobId const& id)
{
std::unique_lock uniqueLock(_jobMutex);
Expand All @@ -75,14 +85,21 @@ std::variant<PersisterJobResult, PersisterJobError> _PersisterWorker::fetchJobRe
THROW_NOT_IMPLEMENTED();
}

void _PersisterWorker::addJob(PersisterJob const& job)
std::vector<PersisterErrorInfo> _PersisterWorker::fetchCriticalErrorInfos()
{
{
std::unique_lock uniqueLock(_jobMutex);

_openJobs.emplace_back(job);
std::unique_lock lock(_jobMutex);

std::vector<PersisterErrorInfo> result;
std::deque<PersisterJobError> 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<std::mutex>& lock)
Expand Down Expand Up @@ -142,14 +159,16 @@ std::variant<PersisterJobResult, PersisterJobError> _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);
Expand Down
3 changes: 2 additions & 1 deletion source/PersisterImpl/PersisterWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ class _PersisterWorker

bool isBusy() const;
PersisterJobState getJobState(PersisterJobId const& id) const;
std::variant<PersisterJobResult, PersisterJobError> fetchJobResult(PersisterJobId const& id);

void addJob(PersisterJob const& job);
std::variant<PersisterJobResult, PersisterJobError> fetchJobResult(PersisterJobId const& id);
std::vector<PersisterErrorInfo> fetchCriticalErrorInfos();

private:
void processJobs(std::unique_lock<std::mutex>& lock);
Expand Down
4 changes: 2 additions & 2 deletions source/PersisterInterface/PersisterController.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class _PersisterController

virtual bool isBusy() const = 0;
virtual PersisterJobState getJobState(PersisterJobId const& id) const = 0;
virtual std::vector<PersisterErrorInfo> fetchErrorInfos() = 0;
virtual std::vector<PersisterErrorInfo> 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;
Expand Down

0 comments on commit fc8597c

Please sign in to comment.