diff --git a/src/main.c b/src/main.c index bee69ff0..ad331d47 100644 --- a/src/main.c +++ b/src/main.c @@ -1008,6 +1008,23 @@ static void _error_handler(int sig) _exit(1); } +#if defined(_WIN32) +static LONG WINAPI _win32_exception_handler(EXCEPTION_POINTERS* info) +{ + if (info->ExceptionRecord->ExceptionCode == STATUS_ACCESS_VIOLATION || + info->ExceptionRecord->ExceptionCode == STATUS_ILLEGAL_INSTRUCTION || + info->ExceptionRecord->ExceptionCode == STATUS_STACK_OVERFLOW || + info->ExceptionRecord->ExceptionCode == STATUS_HEAP_CORRUPTION) + { + const char* stack = tf_util_backtrace_string(); + tf_printf("ERROR:\n%s\n", stack); + tf_free((void*)stack); + _exit(1); + } + return EXCEPTION_CONTINUE_SEARCH; +} +#endif + static void _startup(int argc, char* argv[]) { char buffer[8] = { 0 }; @@ -1055,6 +1072,10 @@ static void _startup(int argc, char* argv[]) perror("signal"); } } + +#if defined(_WIN32) + AddVectoredExceptionHandler(0, _win32_exception_handler); +#endif } #if defined(__ANDROID__)