diff options
author | terkhen <terkhen@openttd.org> | 2011-05-15 14:51:06 +0000 |
---|---|---|
committer | terkhen <terkhen@openttd.org> | 2011-05-15 14:51:06 +0000 |
commit | 003dee6e382369eb506adae74c61a9109d400563 (patch) | |
tree | 655eaa68b79cfa81d971994ea480017eaa1513ca /src/os/windows | |
parent | 4c63d8e82f385dfad5aa407717234df30bc85a0b (diff) | |
download | openttd-003dee6e382369eb506adae74c61a9109d400563.tar.xz |
(svn r22464) -Fix [FS#4587]: [Windows] Prevent a crash when launching OpenTTD with -d from a MSYS console. Added a note to known-bugs about this issue.
Diffstat (limited to 'src/os/windows')
-rw-r--r-- | src/os/windows/win32.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/os/windows/win32.cpp b/src/os/windows/win32.cpp index a66d3d65c..54c5c9cd3 100644 --- a/src/os/windows/win32.cpp +++ b/src/os/windows/win32.cpp @@ -297,7 +297,21 @@ void CreateConsole() /* redirect unbuffered STDIN, STDOUT, STDERR to the console */ #if !defined(__CYGWIN__) - *stdout = *_fdopen( _open_osfhandle((intptr_t)hand, _O_TEXT), "w" ); + + /* Check if we can open a handle to STDOUT. */ + int fd = _open_osfhandle((intptr_t)hand, _O_TEXT); + if (fd == -1) { + /* Free everything related to the console. */ + FreeConsole(); + _has_console = false; + _close(fd); + CloseHandle(hand); + + ShowInfo("Unable to open an output handle to the console. Check known-bugs.txt for details."); + return; + } + + *stdout = *_fdopen(fd, "w"); *stdin = *_fdopen(_open_osfhandle((intptr_t)GetStdHandle(STD_INPUT_HANDLE), _O_TEXT), "r" ); *stderr = *_fdopen(_open_osfhandle((intptr_t)GetStdHandle(STD_ERROR_HANDLE), _O_TEXT), "w" ); #else |