Unify inspector and console panel actions
This commit is contained in:
51
editor/src/Platform/WindowsProcessDiagnostics.h
Normal file
51
editor/src/Platform/WindowsProcessDiagnostics.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user