diff --git a/src/platform/platform.h b/src/platform/platform.h index c3bcc90ae4..84b772dbaf 100644 --- a/src/platform/platform.h +++ b/src/platform/platform.h @@ -204,6 +204,7 @@ datetime64 platform_get_datetime_now_utc(); #undef GetMessage void platform_windows_open_console(); + void platform_windows_close_console(); int windows_get_registry_install_info(rct2_install_info *installInfo, char *source, char *font, uint8 charset); HWND windows_get_window_handle(); void platform_setup_file_associations(); diff --git a/src/platform/shared.c b/src/platform/shared.c index f71e61ecc5..a52b16014b 100644 --- a/src/platform/shared.c +++ b/src/platform/shared.c @@ -639,6 +639,10 @@ void platform_free() platform_close_window(); SDL_Quit(); + +#ifdef __WINDOWS__ + platform_windows_close_console(); +#endif } void platform_start_text_input(utf8* buffer, int max_length) diff --git a/src/platform/windows.c b/src/platform/windows.c index 7722b5b93d..4a8585dfb1 100644 --- a/src/platform/windows.c +++ b/src/platform/windows.c @@ -42,8 +42,9 @@ // The name of the mutex used to prevent multiple instances of the game from running #define SINGLE_INSTANCE_MUTEX_NAME "RollerCoaster Tycoon 2_GSKMUTEX" -utf8 _userDataDirectoryPath[MAX_PATH] = { 0 }; -utf8 _openrctDataDirectoryPath[MAX_PATH] = { 0 }; +static utf8 _userDataDirectoryPath[MAX_PATH] = { 0 }; +static utf8 _openrctDataDirectoryPath[MAX_PATH] = { 0 }; +static bool _consoleIsAttached = false; utf8 **windows_get_command_line_args(int *outNumArgs); @@ -146,12 +147,23 @@ __declspec(dllexport) int StartOpenRCT(HINSTANCE hInstance, HINSTANCE hPrevInsta void platform_windows_open_console() { if (!AttachConsole(ATTACH_PARENT_PROCESS)) { - AllocConsole(); + if (!AllocConsole()) { + return; + } } freopen("CONIN$", "r", stdin); freopen("CONOUT$", "w", stdout); freopen("CONOUT$", "w", stderr); + _consoleIsAttached = true; +} + +void platform_windows_close_console() +{ + if (_consoleIsAttached) { + _consoleIsAttached = false; + FreeConsole(); + } } utf8 **windows_get_command_line_args(int *outNumArgs)