OpenToonz - An open-source full-featured 2D animation creation software
C
Catch TException messages
justburner41a8e87dd8b1
diff --git a/toonz/sources/common/tcore/texception.cpp b/toonz/sources/common/tcore/texception.cppindex c5cab1528..fe1b4681b 100644--- a/toonz/sources/common/tcore/texception.cpp+++ b/toonz/sources/common/tcore/texception.cpp@@ -3,7 +3,15 @@#include "texception.h"#include "tconvert.h"-TException::TException(const std::string &msg) { m_msg = ::to_wstring(msg); }+static TString s_lastMsg;++TException::TException(const std::string &msg) {+ m_msg = ::to_wstring(msg);+ s_lastMsg = getMessage();+}++TString TException::getLastMessage() { return s_lastMsg; }+/*ostream& operator<<(ostream &out, const TException &e){diff --git a/toonz/sources/common/tcore/tstring.cpp b/toonz/sources/common/tcore/tstring.cppindex 743db4b21..928918b76 100644--- a/toonz/sources/common/tcore/tstring.cpp+++ b/toonz/sources/common/tcore/tstring.cpp@@ -18,13 +18,6 @@#include <sstream>-class TStringConvertException final : public TException {- std::string m_string;--public:- TStringConvertException(const std::string str) : m_string(str) {}-};-std::wstring to_wstring(std::string s) {#ifdef TNZCORE_LIGHTstd::wstring ws;diff --git a/toonz/sources/include/texception.h b/toonz/sources/include/texception.hindex 30b1ed1d3..ec79033e6 100644--- a/toonz/sources/include/texception.h+++ b/toonz/sources/include/texception.h@@ -23,6 +23,7 @@ public:explicit TException(const std::wstring &msg) : m_msg(msg) {}virtual ~TException() {}virtual TString getMessage() const { return m_msg; }+ static TString getLastMessage();};// DVAPI ostream& operator<<(ostream &out, const TException &e);diff --git a/toonz/sources/toonz/crashhandler.cpp b/toonz/sources/toonz/crashhandler.cppindex 3e5db27b8..c56f03bf4 100644--- a/toonz/sources/toonz/crashhandler.cpp+++ b/toonz/sources/toonz/crashhandler.cpp@@ -20,6 +20,7 @@#include "tapp.h"#include "tenv.h"#include "tconvert.h"+#include "texception.h"#include "tfilepath_io.h"#include "toonz/toonzfolders.h"#include "toonz/tproject.h"@@ -204,9 +205,6 @@ LONG WINAPI exceptionHandler(PEXCEPTION_POINTERS info) {case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:reason = "EXCEPTION_ARRAY_BOUNDS_EXCEEDED";break;- //case EXCEPTION_BREAKPOINT:- // reason = "EXCEPTION_BREAKPOINT";- // break;case EXCEPTION_DATATYPE_MISALIGNMENT:reason = "EXCEPTION_DATATYPE_MISALIGNMENT";break;@@ -240,9 +238,6 @@ LONG WINAPI exceptionHandler(PEXCEPTION_POINTERS info) {case EXCEPTION_INT_DIVIDE_BY_ZERO:reason = "EXCEPTION_INT_DIVIDE_BY_ZERO";break;- //case EXCEPTION_INT_OVERFLOW:- // reason = "EXCEPTION_INT_OVERFLOW";- // break;case EXCEPTION_INVALID_DISPOSITION:reason = "EXCEPTION_INVALID_DISPOSITION";break;@@ -252,19 +247,19 @@ LONG WINAPI exceptionHandler(PEXCEPTION_POINTERS info) {case EXCEPTION_PRIV_INSTRUCTION:reason = "EXCEPTION_PRIV_INSTRUCTION";break;- //case EXCEPTION_SINGLE_STEP:- // reason = "EXCEPTION_SINGLE_STEP";- // break;case EXCEPTION_STACK_OVERFLOW:reason = "EXCEPTION_STACK_OVERFLOW";break;+ case 0xE06D7363: // Magic number... oof+ reason = "C++ Exception";+ break;default:- return EXCEPTION_CONTINUE_EXECUTION;+ return EXCEPTION_CONTINUE_SEARCH;}if (CrashHandler::trigger(reason, true)) _Exit(1);- return EXCEPTION_CONTINUE_EXECUTION;+ return EXCEPTION_CONTINUE_SEARCH;}#endif@@ -530,19 +525,19 @@ bool CrashHandler::trigger(const QString reason, bool showDialog) {// Generate minidumpbool minidump = generateMinidump(fpDump);- TProjectManager *pm = TProjectManager::instance();- TProjectP currentProject = pm->getCurrentProject();- TFilePath projectPath = currentProject->getProjectPath();- ToonzScene *currentScene = TApp::instance()->getCurrentScene()->getScene();- std::wstring sceneName = currentScene->getSceneName();-// Generate reporttry {+ TString exception = TException::getLastMessage();+out.append(TEnv::getApplicationFullName() + " (Build " + __DATE__ ")\n");out.append("\nReport Date: ");out.append(dateName);out.append("\nCrash Reason: ");out.append(reason.toStdString());+ if (!exception.empty()) {+ out.append("\nException: ");+ out.append(::to_string(exception));+ }out.append("\n\n");printSysInfo(out);out.append("\n");@@ -556,6 +551,18 @@ bool CrashHandler::trigger(const QString reason, bool showDialog) {elseout.append("Failed");#endif+ out.append("\n");+ } catch (...) {+ }+ try {+ TProjectManager *pm = TProjectManager::instance();++ TProjectP currentProject = pm->getCurrentProject();+ TFilePath projectPath = currentProject->getProjectPath();++ ToonzScene *currentScene = TApp::instance()->getCurrentScene()->getScene();+ std::wstring sceneName = currentScene->getSceneName();+out.append("\nApplication Dir: ");out.append(QCoreApplication::applicationDirPath().toStdString());out.append("\nStuff Dir: ");@@ -570,18 +577,24 @@ bool CrashHandler::trigger(const QString reason, bool showDialog) {out.append("\nScene Path: ");out.append(currentScene->getScenePath().getQString().toStdString());out.append("\n");+ } catch (...) {+ }#ifdef HAS_MODULES+ try {out.append("\n==== Modules ====\n");printModules(out);out.append("==== End ====\n");+ } catch (...) {+ }#endif#ifdef HAS_BACKTRACE+ try {out.append("\n==== Backtrace ====\n");printBacktrace(out);out.append("==== End ====\n");-#endif} catch (...) {}+#endif// Save to crash information to fileFILE *fw = fopen(fpCrsh, "w");