Merge pull request #188 from diamante0018/feature/new-exception-coby
[Exception] Refactor component & copy exception message to clipboard
This commit is contained in:
commit
2ac69b02a0
@ -43,10 +43,10 @@ namespace Components
|
|||||||
Utils::Time::Interval interval;
|
Utils::Time::Interval interval;
|
||||||
while (IsWindow(Window::GetWindow()) != FALSE && !interval.elapsed(2s))
|
while (IsWindow(Window::GetWindow()) != FALSE && !interval.elapsed(2s))
|
||||||
{
|
{
|
||||||
if (PeekMessage(&msg, nullptr, NULL, NULL, PM_REMOVE))
|
if (PeekMessageA(&msg, nullptr, NULL, NULL, PM_REMOVE))
|
||||||
{
|
{
|
||||||
TranslateMessage(&msg);
|
TranslateMessage(&msg);
|
||||||
DispatchMessage(&msg);
|
DispatchMessageA(&msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::this_thread::sleep_for(10ms);
|
std::this_thread::sleep_for(10ms);
|
||||||
@ -57,6 +57,35 @@ namespace Components
|
|||||||
Game::Sys_SuspendOtherThreads();
|
Game::Sys_SuspendOtherThreads();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Exception::CopyMessageToClipboard(const std::string& error)
|
||||||
|
{
|
||||||
|
const auto hWndNewOwner = GetDesktopWindow();
|
||||||
|
const auto result = OpenClipboard(hWndNewOwner);
|
||||||
|
|
||||||
|
if (result == FALSE)
|
||||||
|
return;
|
||||||
|
|
||||||
|
EmptyClipboard();
|
||||||
|
auto* hMem = GlobalAlloc(GMEM_MOVEABLE, error.size() + 1);
|
||||||
|
|
||||||
|
if (hMem == nullptr)
|
||||||
|
{
|
||||||
|
CloseClipboard();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto lock = GlobalLock(hMem);
|
||||||
|
if (lock != nullptr)
|
||||||
|
{
|
||||||
|
std::memcpy(lock, error.data(), error.size() + 1);
|
||||||
|
GlobalUnlock(hMem);
|
||||||
|
SetClipboardData(1, hMem);
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseClipboard();
|
||||||
|
GlobalFree(hMem);
|
||||||
|
}
|
||||||
|
|
||||||
LONG WINAPI Exception::ExceptionFilter(LPEXCEPTION_POINTERS ExceptionInfo)
|
LONG WINAPI Exception::ExceptionFilter(LPEXCEPTION_POINTERS ExceptionInfo)
|
||||||
{
|
{
|
||||||
// Pass on harmless errors
|
// Pass on harmless errors
|
||||||
@ -69,16 +98,20 @@ namespace Components
|
|||||||
std::string errorStr;
|
std::string errorStr;
|
||||||
if (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_STACK_OVERFLOW)
|
if (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_STACK_OVERFLOW)
|
||||||
{
|
{
|
||||||
errorStr = "Termination because of a stack overflow.";
|
errorStr = "Termination because of a stack overflow.\nCopy exception address to clipboard?";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
errorStr = Utils::String::VA("Fatal error (0x%08X) at 0x%08X.", ExceptionInfo->ExceptionRecord->ExceptionCode, ExceptionInfo->ExceptionRecord->ExceptionAddress);
|
errorStr = Utils::String::VA("Fatal error (0x%08X) at 0x%08X.\nCopy exception address to clipboard?", ExceptionInfo->ExceptionRecord->ExceptionCode, ExceptionInfo->ExceptionRecord->ExceptionAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Exception::SuspendProcess();
|
//Exception::SuspendProcess();
|
||||||
|
|
||||||
MessageBoxA(nullptr, errorStr.data(), "ERROR", MB_ICONERROR);
|
// Message should be copied to the keyboard if no button is pressed
|
||||||
|
if (MessageBoxA(nullptr, errorStr.data(), nullptr, MB_YESNO | MB_ICONERROR) == IDYES)
|
||||||
|
{
|
||||||
|
Exception::CopyMessageToClipboard(Utils::String::VA("0x%08X", ExceptionInfo->ExceptionRecord->ExceptionAddress));
|
||||||
|
}
|
||||||
|
|
||||||
if (Flags::HasFlag("bigminidumps"))
|
if (Flags::HasFlag("bigminidumps"))
|
||||||
{
|
{
|
||||||
@ -172,8 +205,8 @@ namespace Components
|
|||||||
// Display DEBUG branding, so we know we're on a debug build
|
// Display DEBUG branding, so we know we're on a debug build
|
||||||
Scheduler::OnFrame([]()
|
Scheduler::OnFrame([]()
|
||||||
{
|
{
|
||||||
Game::Font_s* font = Game::R_RegisterFont("fonts/normalFont", 0);
|
auto* font = Game::R_RegisterFont("fonts/normalFont", 0);
|
||||||
float color[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
Game::vec4_t color = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||||
|
|
||||||
// Change the color when attaching a debugger
|
// Change the color when attaching a debugger
|
||||||
if (IsDebuggerPresent())
|
if (IsDebuggerPresent())
|
||||||
@ -201,12 +234,12 @@ namespace Components
|
|||||||
Game::UI_UpdateArenas();
|
Game::UI_UpdateArenas();
|
||||||
|
|
||||||
std::string command;
|
std::string command;
|
||||||
for (int i = 0; i < (params->length() >= 2 ? atoi(params->get(1)) : *Game::arenaCount); ++i)
|
for (auto i = 0; i < (params->length() >= 2 ? atoi(params->get(1)) : *Game::arenaCount); ++i)
|
||||||
{
|
{
|
||||||
char* mapname = ArenaLength::NewArenas[i % *Game::arenaCount].mapName;
|
const auto* mapname = ArenaLength::NewArenas[i % *Game::arenaCount].mapName;
|
||||||
|
|
||||||
if (!(i % 2)) command.append(Utils::String::VA("wait 250;disconnect;wait 750;", mapname)); // Test a disconnect
|
if (!(i % 2)) command.append("wait 250;disconnect;wait 750;"); // Test a disconnect
|
||||||
else command.append(Utils::String::VA("wait 500;", mapname)); // Test direct map switch
|
else command.append("wait 500;"); // Test direct map switch
|
||||||
command.append(Utils::String::VA("map %s;", mapname));
|
command.append(Utils::String::VA("map %s;", mapname));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,8 @@ namespace Components
|
|||||||
static LPTOP_LEVEL_EXCEPTION_FILTER WINAPI SetUnhandledExceptionFilterStub(LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter);
|
static LPTOP_LEVEL_EXCEPTION_FILTER WINAPI SetUnhandledExceptionFilterStub(LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter);
|
||||||
static __declspec(noreturn) void ErrorLongJmp(jmp_buf _Buf, int _Value);
|
static __declspec(noreturn) void ErrorLongJmp(jmp_buf _Buf, int _Value);
|
||||||
static __declspec(noreturn) void LongJmp(jmp_buf _Buf, int _Value);
|
static __declspec(noreturn) void LongJmp(jmp_buf _Buf, int _Value);
|
||||||
static void DebugMinidumpCommand(Command::Params*);
|
|
||||||
|
static void CopyMessageToClipboard(const std::string& error);
|
||||||
|
|
||||||
static int MiniDumpType;
|
static int MiniDumpType;
|
||||||
static Utils::Hook SetFilterHook;
|
static Utils::Hook SetFilterHook;
|
||||||
|
Loading…
Reference in New Issue
Block a user