2018-07-21 15:40:16 -07:00
|
|
|
#include "mainwindow.h"
|
2018-11-27 15:54:04 -05:00
|
|
|
#include "host/util.h"
|
2018-09-01 15:31:18 -04:00
|
|
|
#include <sstream>
|
2018-07-21 15:40:16 -07:00
|
|
|
#include <QApplication>
|
2018-12-01 15:55:32 -05:00
|
|
|
#include <QDir>
|
2018-07-21 15:40:16 -07:00
|
|
|
|
2018-11-25 16:45:43 -05:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
char* GetCppExceptionInfo(EXCEPTION_POINTERS* exception)
|
|
|
|
{
|
|
|
|
// See https://blogs.msdn.microsoft.com/oldnewthing/20100730-00/?p=13273
|
|
|
|
// Not very reliable so use __try
|
|
|
|
__try { return ((char****)exception->ExceptionRecord->ExceptionInformation[2])[3][1][1] + 8; }
|
|
|
|
__except (EXCEPTION_EXECUTE_HANDLER) { return "Could not find"; }
|
|
|
|
}
|
|
|
|
|
2018-11-25 19:06:38 -05:00
|
|
|
thread_local std::wstring lastError = L"Unknown error";
|
|
|
|
|
2018-12-01 15:55:32 -05:00
|
|
|
__declspec(noreturn) void Terminate()
|
|
|
|
{
|
|
|
|
MessageBoxW(NULL, lastError.c_str(), L"Textractor ERROR", MB_ICONERROR);
|
|
|
|
std::abort();
|
|
|
|
}
|
|
|
|
|
2018-11-25 19:06:38 -05:00
|
|
|
LONG WINAPI ExceptionLogger(EXCEPTION_POINTERS* exception)
|
2018-11-25 16:45:43 -05:00
|
|
|
{
|
2018-12-01 15:55:32 -05:00
|
|
|
thread_local static auto terminateSetter = std::invoke(std::set_terminate, Terminate);
|
|
|
|
|
2018-11-25 16:45:43 -05:00
|
|
|
MEMORY_BASIC_INFORMATION info = {};
|
|
|
|
VirtualQuery(exception->ExceptionRecord->ExceptionAddress, &info, sizeof(info));
|
|
|
|
|
|
|
|
std::wstringstream errorMsg;
|
|
|
|
errorMsg << std::uppercase << std::hex <<
|
|
|
|
L"Error code: " << exception->ExceptionRecord->ExceptionCode << std::endl <<
|
2018-11-27 15:54:04 -05:00
|
|
|
L"Error address: " << exception->ExceptionRecord->ExceptionAddress << std::endl <<
|
|
|
|
L"Error in module: " << Util::GetModuleFileName((HMODULE)info.AllocationBase).value_or(L"Could not find") << std::endl <<
|
|
|
|
L"Additional info: " << info.AllocationBase << std::endl;
|
2018-11-25 16:45:43 -05:00
|
|
|
|
2018-11-27 21:29:09 -05:00
|
|
|
if (exception->ExceptionRecord->ExceptionCode == 0xE06D7363)
|
2018-11-25 16:45:43 -05:00
|
|
|
errorMsg << L"Additional info: " << GetCppExceptionInfo(exception) << std::endl;
|
|
|
|
|
|
|
|
for (int i = 0; i < exception->ExceptionRecord->NumberParameters; ++i)
|
|
|
|
errorMsg << L"Additional info: " << exception->ExceptionRecord->ExceptionInformation[i] << std::endl;
|
|
|
|
|
2018-11-25 19:06:38 -05:00
|
|
|
lastError = errorMsg.str();
|
2018-11-25 16:45:43 -05:00
|
|
|
return EXCEPTION_CONTINUE_SEARCH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-21 15:40:16 -07:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2018-11-25 19:06:38 -05:00
|
|
|
AddVectoredExceptionHandler(FALSE, ExceptionLogger);
|
2018-11-27 15:54:04 -05:00
|
|
|
SetUnhandledExceptionFilter([](auto) -> LONG { Terminate(); });
|
|
|
|
|
2018-12-02 02:57:03 -05:00
|
|
|
QDir::setCurrent(QFileInfo(QString::fromStdWString(Util::GetModuleFileName().value())).absolutePath());
|
2018-11-27 15:54:04 -05:00
|
|
|
|
2018-08-22 12:44:16 -04:00
|
|
|
QApplication a(argc, argv);
|
|
|
|
MainWindow w;
|
|
|
|
w.show();
|
2018-08-22 12:44:53 -04:00
|
|
|
return a.exec();
|
2018-07-21 15:40:16 -07:00
|
|
|
}
|