Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/exception2 #250

Merged
merged 4 commits into from Sep 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,14 @@
Here we document changes that affect the public API or changes that needs to be communicated to other developers.

## 2018-09-21
Settings are no longer shared between executables. I.e. The Inviwo app and the integration test will not use the same settings any more. We now prefix the settings with the InviwoApplication display name. This also implies that any existing Inviwo app settings will be lost. To keep old setting one can prefix all the ".ivs" file in the inviwo settings folder with "Inviwo_". On windows the inviwo settings can be found in %APPDATA%/inviwo.

Added System settings for breaking into the debugger on various log message levels, and on throwing exceptions. Also added an option to add stacktraces to exceptions. All to help with debugging.

The inviwo app will now catch uncaught inviwo exceptions in main and present an dialog with information and an option to continue or abort. It will also give an option to save your workspace before closing.

InviwoApplicationQt now has the same order of constructor arguments as InviwoApplication.

## 2018-08-21
The property class identifier system no longer uses the `InviwoPropertyInfo` / `PropertyClassIdentifier` macros but rather implements
```
Expand Down
65 changes: 54 additions & 11 deletions apps/inviwo/inviwo.cpp
Expand Up @@ -35,12 +35,15 @@
#include <inviwo/core/util/logerrorcounter.h>
#include <inviwo/core/util/raiiutils.h>
#include <inviwo/core/network/processornetwork.h>
#include <inviwo/core/util/raiiutils.h>
#include <inviwo/core/util/ostreamjoiner.h>
#include <inviwo/qt/editor/inviwomainwindow.h>
#include <inviwo/core/util/filelogger.h>
#include "inviwosplashscreen.h"
#include <moduleregistration.h>

#include <sstream>
#include <algorithm>

#include <warn/push>
#include <warn/ignore/all>
#include <QFile>
Expand All @@ -52,7 +55,7 @@ int main(int argc, char** argv) {
inviwo::LogCentral::init(&logger);
auto logCounter = std::make_shared<inviwo::LogErrorCounter>();
logger.registerLogger(logCounter);
inviwo::InviwoApplicationQt inviwoApp("Inviwo", argc, argv);
inviwo::InviwoApplicationQt inviwoApp(argc, argv, "Inviwo");
inviwoApp.setWindowIcon(QIcon(":/inviwo/inviwo_light.png"));
inviwoApp.setAttribute(Qt::AA_NativeWindows);
QFile styleSheetFile(":/stylesheets/inviwo.qss");
Expand Down Expand Up @@ -107,21 +110,61 @@ int main(int argc, char** argv) {
logCounter.reset();

// process last arguments
if (!clp.getQuitApplicationAfterStartup()) {
if (clp.getQuitApplicationAfterStartup()) {
mainWin.exitInviwo(false);
return 0;
}

while (true) {
try {
return inviwoApp.exec();
} catch (const inviwo::Exception& e) {
inviwo::util::log(e.getContext(), e.getMessage());
QMessageBox::critical(nullptr, "Fatal Error", QString::fromStdString(e.getMessage()));
{
inviwo::util::log(e.getContext(), e.getMessage());
std::stringstream ss;
auto j = inviwo::util::make_ostream_joiner(ss, "\n");
std::copy(e.getStack().begin(), e.getStack().end(), j);
LogErrorCustom("Inviwo", ss.str());
}
{
std::stringstream ss;
ss << e.getMessage();
if (!e.getStack().empty()) {
ss << "\nStack Trace:\n";
auto j = inviwo::util::make_ostream_joiner(ss, "\n");
if (std::distance(e.getStack().begin(), e.getStack().end()) > 10) {
std::copy(e.getStack().begin(), e.getStack().begin() + 10, j);
ss << "\n...";
} else {
std::copy(e.getStack().begin(), e.getStack().end(), j);
}
}
ss << "\nApplication state might be corrupted, be warned.";
auto res = QMessageBox::critical(
&mainWin, "Fatal Error", QString::fromStdString(ss.str()),
QMessageBox::Ignore | QMessageBox::Close, QMessageBox::Close);
if (res == QMessageBox::Close) {
mainWin.askToSaveWorkspaceChanges();
return 1;
}
}

} catch (const std::exception& e) {
LogErrorCustom("inviwo.cpp", e.what());
QMessageBox::critical(nullptr, "Fatal Error", e.what());
LogErrorCustom("Inviwo", e.what());
std::stringstream ss;
ss << e.what();
ss << "\nApplication state might be corrupted, be warned.";
auto res =
QMessageBox::critical(&mainWin, "Fatal Error", QString::fromStdString(ss.str()),
QMessageBox::Ignore | QMessageBox::Close, QMessageBox::Close);
if (res == QMessageBox::Close) {
mainWin.askToSaveWorkspaceChanges();
return 1;
}
} catch (...) {
LogErrorCustom("inviwo.cpp", "Uncaught exception, terminating");
LogErrorCustom("Inviwo", "Uncaught exception, terminating");
QMessageBox::critical(nullptr, "Fatal Error", "Uncaught exception, terminating");
return 1;
}
} else {
mainWin.exitInviwo(false);
return 0;
}
}
2 changes: 1 addition & 1 deletion apps/minimals/glfw/glfwminimum.cpp
Expand Up @@ -56,7 +56,7 @@ int main(int argc, char** argv) {
auto logger = std::make_shared<inviwo::ConsoleLogger>();
LogCentral::getPtr()->registerLogger(logger);

InviwoApplication inviwoApp(argc, argv, "Inviwo v" + IVW_VERSION + " - GLFWApp");
InviwoApplication inviwoApp(argc, argv, "Inviwo-GLFW");
inviwoApp.printApplicationInfo();
inviwoApp.setPostEnqueueFront([]() { glfwPostEmptyEvent(); });
inviwoApp.setProgressCallback([](std::string m) {
Expand Down
3 changes: 1 addition & 2 deletions apps/minimals/qt/qtminimum.cpp
Expand Up @@ -49,8 +49,7 @@ int main(int argc, char** argv) {
auto logger = std::make_shared<inviwo::ConsoleLogger>();
LogCentral::getPtr()->registerLogger(logger);

std::string appName = "Inviwo v" + IVW_VERSION + " - QtApp";
InviwoApplicationQt inviwoApp(appName, argc, argv);
InviwoApplicationQt inviwoApp(argc, argv, "Inviwo-Qt");
inviwoApp.printApplicationInfo();
inviwoApp.setAttribute(Qt::AA_NativeWindows);
inviwoApp.setProgressCallback([](std::string m) {
Expand Down