52 lines
1.3 KiB
C
52 lines
1.3 KiB
C
|
|
#pragma once
|
||
|
|
|
||
|
|
#include "Platform/Win32Utf8.h"
|
||
|
|
|
||
|
|
#include <stdio.h>
|
||
|
|
#include <string>
|
||
|
|
#include <windows.h>
|
||
|
|
|
||
|
|
namespace XCEngine {
|
||
|
|
namespace Editor {
|
||
|
|
namespace Platform {
|
||
|
|
|
||
|
|
inline std::string GetExecutableLogPath(const char* fileName) {
|
||
|
|
return GetExecutableDirectoryUtf8() + "\\" + fileName;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline LONG WINAPI CrashExceptionFilter(EXCEPTION_POINTERS* exceptionPointers) {
|
||
|
|
const std::string logPath = GetExecutableLogPath("crash.log");
|
||
|
|
|
||
|
|
FILE* file = nullptr;
|
||
|
|
fopen_s(&file, logPath.c_str(), "a");
|
||
|
|
if (file) {
|
||
|
|
fprintf(
|
||
|
|
file,
|
||
|
|
"[CRASH] ExceptionCode=0x%08X, Address=0x%p\n",
|
||
|
|
exceptionPointers->ExceptionRecord->ExceptionCode,
|
||
|
|
exceptionPointers->ExceptionRecord->ExceptionAddress);
|
||
|
|
fclose(file);
|
||
|
|
}
|
||
|
|
|
||
|
|
fprintf(
|
||
|
|
stderr,
|
||
|
|
"[CRASH] ExceptionCode=0x%08X, Address=0x%p\n",
|
||
|
|
exceptionPointers->ExceptionRecord->ExceptionCode,
|
||
|
|
exceptionPointers->ExceptionRecord->ExceptionAddress);
|
||
|
|
|
||
|
|
return EXCEPTION_EXECUTE_HANDLER;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline void InstallCrashExceptionFilter() {
|
||
|
|
SetUnhandledExceptionFilter(CrashExceptionFilter);
|
||
|
|
}
|
||
|
|
|
||
|
|
inline void RedirectStderrToExecutableLog() {
|
||
|
|
const std::string stderrPath = GetExecutableLogPath("stderr.log");
|
||
|
|
freopen(stderrPath.c_str(), "w", stderr);
|
||
|
|
}
|
||
|
|
|
||
|
|
} // namespace Platform
|
||
|
|
} // namespace Editor
|
||
|
|
} // namespace XCEngine
|