From 391bea155c6bdac61b540f7831e988260c02c072 Mon Sep 17 00:00:00 2001 From: Chris Djali Date: Tue, 4 May 2021 00:07:24 +0100 Subject: [PATCH] Catch and rethrow .NET exceptions in OMODFrameworkWrapper constructor Otherwise things like trying to load OMODFramework DLLs with a zone identifier (e.g. because I've asked someone to try something with a modified version to debug an issue) will generate a .NET exception and crash MO2, producing an undebuggable crash dump. Mixed mode and native see only external code, and managed insists the crash is in native code without preserving the exception that native code threw. --- src/OMODFrameworkWrapper.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/OMODFrameworkWrapper.cpp b/src/OMODFrameworkWrapper.cpp index f64b7fc..e5a3cb2 100644 --- a/src/OMODFrameworkWrapper.cpp +++ b/src/OMODFrameworkWrapper.cpp @@ -70,17 +70,28 @@ OMODFrameworkWrapper::OMODFrameworkWrapper(MOBase::IOrganizer* organizer, QWidge , mParentWidget(parentWidget) , mWaitDialog(make_nullptr()) { - AssemblyResolver::initialise(mMoInfo); + try + { + AssemblyResolver::initialise(mMoInfo); - constructorHelper(); + constructorHelper(); - connect(this, &OMODFrameworkWrapper::pickModName, this, &OMODFrameworkWrapper::pickModNameSlot, Qt::ConnectionType::BlockingQueuedConnection); - connect(this, &OMODFrameworkWrapper::createMod, this, &OMODFrameworkWrapper::createModSlot, Qt::ConnectionType::BlockingQueuedConnection); - connect(this, &OMODFrameworkWrapper::displayReadme, this, &OMODFrameworkWrapper::displayReadmeSlot, Qt::ConnectionType::BlockingQueuedConnection); - connect(this, &OMODFrameworkWrapper::showWaitDialog, this, &OMODFrameworkWrapper::showWaitDialogSlot, Qt::ConnectionType::QueuedConnection); - connect(this, &OMODFrameworkWrapper::hideWaitDialog, this, &OMODFrameworkWrapper::hideWaitDialogSlot, Qt::ConnectionType::QueuedConnection); + connect(this, &OMODFrameworkWrapper::pickModName, this, &OMODFrameworkWrapper::pickModNameSlot, Qt::ConnectionType::BlockingQueuedConnection); + connect(this, &OMODFrameworkWrapper::createMod, this, &OMODFrameworkWrapper::createModSlot, Qt::ConnectionType::BlockingQueuedConnection); + connect(this, &OMODFrameworkWrapper::displayReadme, this, &OMODFrameworkWrapper::displayReadmeSlot, Qt::ConnectionType::BlockingQueuedConnection); + connect(this, &OMODFrameworkWrapper::showWaitDialog, this, &OMODFrameworkWrapper::showWaitDialogSlot, Qt::ConnectionType::QueuedConnection); + connect(this, &OMODFrameworkWrapper::hideWaitDialog, this, &OMODFrameworkWrapper::hideWaitDialogSlot, Qt::ConnectionType::QueuedConnection); - initFrameworkSettings(); + initFrameworkSettings(); + } + catch (const std::exception& e) + { + throw; + } + catch (System::Exception^ dotNetException) + { + throw toStdException(dotNetException); + } } void OMODFrameworkWrapper::constructorHelper()