feat: overhaul editor console panel and diagnostics
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
|
||||
#include "Platform/Win32Utf8.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <crtdbg.h>
|
||||
#endif
|
||||
#include <dbghelp.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
@@ -15,6 +18,46 @@ inline std::string GetExecutableLogPath(const char* fileName) {
|
||||
return GetExecutableDirectoryUtf8() + "\\" + fileName;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
inline void WriteInvalidParameterReport(
|
||||
const wchar_t* expression,
|
||||
const wchar_t* function,
|
||||
const wchar_t* file,
|
||||
unsigned int line) {
|
||||
const std::string logPath = GetExecutableLogPath("crash.log");
|
||||
FILE* logFile = nullptr;
|
||||
fopen_s(&logFile, logPath.c_str(), "a");
|
||||
if (logFile != nullptr) {
|
||||
fwprintf(
|
||||
logFile,
|
||||
L"[CRT] Invalid parameter. function=%s file=%s line=%u expression=%s\n",
|
||||
function != nullptr ? function : L"(null)",
|
||||
file != nullptr ? file : L"(null)",
|
||||
line,
|
||||
expression != nullptr ? expression : L"(null)");
|
||||
fclose(logFile);
|
||||
}
|
||||
|
||||
fwprintf(
|
||||
stderr,
|
||||
L"[CRT] Invalid parameter. function=%s file=%s line=%u expression=%s\n",
|
||||
function != nullptr ? function : L"(null)",
|
||||
file != nullptr ? file : L"(null)",
|
||||
line,
|
||||
expression != nullptr ? expression : L"(null)");
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
inline void InvalidParameterHandler(
|
||||
const wchar_t* expression,
|
||||
const wchar_t* function,
|
||||
const wchar_t* file,
|
||||
unsigned int line,
|
||||
uintptr_t) {
|
||||
WriteInvalidParameterReport(expression, function, file, line);
|
||||
}
|
||||
#endif
|
||||
|
||||
inline void WriteCrashStackTrace(FILE* file) {
|
||||
if (file == nullptr) {
|
||||
return;
|
||||
@@ -84,11 +127,24 @@ inline LONG WINAPI CrashExceptionFilter(EXCEPTION_POINTERS* exceptionPointers) {
|
||||
|
||||
inline void InstallCrashExceptionFilter() {
|
||||
SetUnhandledExceptionFilter(CrashExceptionFilter);
|
||||
|
||||
#ifdef _MSC_VER
|
||||
_set_invalid_parameter_handler(InvalidParameterHandler);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void RedirectStderrToExecutableLog() {
|
||||
const std::string stderrPath = GetExecutableLogPath("stderr.log");
|
||||
freopen(stderrPath.c_str(), "w", stderr);
|
||||
|
||||
#ifdef _MSC_VER
|
||||
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
|
||||
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
|
||||
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
|
||||
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
|
||||
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
|
||||
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace Platform
|
||||
|
||||
Reference in New Issue
Block a user