9#if defined(EVENGINE_WINDOWS) || defined(_WIN32)
16#include <backward.hpp>
18#ifndef WER_FAULT_REPORTING_NO_UI
19#define WER_FAULT_REPORTING_NO_UI 0x20
21#ifndef WER_FAULT_REPORTING_ALWAYS_SHOW_UI
22#define WER_FAULT_REPORTING_ALWAYS_SHOW_UI 0x10
35extern "C" __declspec(dllimport) BOOL WINAPI SymInitialize(
36 HANDLE hProcess, PCSTR UserSearchPath, BOOL fInvadeProcess);
46inline LONG WINAPI crashHandler(EXCEPTION_POINTERS *ep) {
50 SymInitialize(GetCurrentProcess(),
nullptr, TRUE);
51 std::ostringstream report;
52 report <<
"[crash] code=0x" << std::hex << std::setw(8) << std::setfill(
'0')
53 << ep->ExceptionRecord->ExceptionCode << std::dec << std::setfill(
' ')
54 <<
" at " << ep->ExceptionRecord->ExceptionAddress <<
"\n";
56 backward::StackTrace st;
64 p.color_mode = backward::ColorMode::never;
67 report <<
"[crash] backtrace unavailable\n";
69 const std::string
text = report.str();
71 std::fputs(
text.c_str(), stderr);
76 return EXCEPTION_CONTINUE_SEARCH;
89inline void installCrashHandler() {
91 SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
93 if (FAILED(WerGetFlags(GetCurrentProcess(), &werFlags))) {
96 (void)WerSetFlags((werFlags | WER_FAULT_REPORTING_NO_UI) &
97 ~static_cast<DWORD>(WER_FAULT_REPORTING_ALWAYS_SHOW_UI));
100 _set_error_mode(_OUT_TO_STDERR);
102 _set_abort_behavior(0, _WRITE_ABORT_MSG);
105 SetUnhandledExceptionFilter(&crashHandler);
Persistent, thread-safe record of engine crash and problem events.
Build metadata (engine git commit, build time, third-party version).
void recordCrashEvent(const std::string &report)
Records a crash report, safe to call from a crash/exception handler.