diff options
author | smatz <smatz@openttd.org> | 2008-06-03 18:35:58 +0000 |
---|---|---|
committer | smatz <smatz@openttd.org> | 2008-06-03 18:35:58 +0000 |
commit | c7a9637834a96722be5a524c4c1e8932a45e3461 (patch) | |
tree | 72b7d141fd63dcb880f610a334390bf9c41f97b1 /src/win32.cpp | |
parent | d58f0558761079552c4c607707dd131a2c5e5397 (diff) | |
download | openttd-c7a9637834a96722be5a524c4c1e8932a45e3461.tar.xz |
(svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
Diffstat (limited to 'src/win32.cpp')
-rw-r--r-- | src/win32.cpp | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/win32.cpp b/src/win32.cpp index 21ddfed03..5fa7edc82 100644 --- a/src/win32.cpp +++ b/src/win32.cpp @@ -25,6 +25,7 @@ #include "core/random_func.hpp" #include "core/bitmath_func.hpp" #include "string_func.h" +#include "gamelog.h" #include <ctype.h> #include <tchar.h> #include <errno.h> @@ -454,6 +455,15 @@ static void Handler2() extern bool CloseConsoleLogIfActive(); +static HANDLE _file_crash_log; + +static void GamelogPrintCrashLogProc(const char *s) +{ + DWORD num_written; + WriteFile(_file_crash_log, s, strlen(s), &num_written, NULL); + WriteFile(_file_crash_log, "\r\n", strlen("\r\n"), &num_written, NULL); +} + static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep) { char *output; @@ -588,17 +598,15 @@ static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep) os.dwOSVersionInfoSize = sizeof(os); GetVersionEx(&os); output += sprintf(output, "\r\nSystem information:\r\n" - " Windows version %d.%d %d %s\r\n", + " Windows version %d.%d %d %s\r\n\r\n", os.dwMajorVersion, os.dwMinorVersion, os.dwBuildNumber, os.szCSDVersion); } - { - HANDLE file = CreateFile(_T("crash.log"), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0); + _file_crash_log = CreateFile(_T("crash.log"), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0); + + if (_file_crash_log != INVALID_HANDLE_VALUE) { DWORD num_written; - if (file != INVALID_HANDLE_VALUE) { - WriteFile(file, _crash_msg, output - _crash_msg, &num_written, NULL); - CloseHandle(file); - } + WriteFile(_file_crash_log, _crash_msg, output - _crash_msg, &num_written, NULL); } #if !defined(_DEBUG) @@ -636,6 +644,11 @@ static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep) } #endif + if (_file_crash_log != INVALID_HANDLE_VALUE) { + GamelogPrint(&GamelogPrintCrashLogProc); + CloseHandle(_file_crash_log); + } + /* Close any possible log files */ CloseConsoleLogIfActive(); |