From 7854c1a0c21193af3992ef672b322a27d41c883d Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Mon, 1 Oct 2012 15:59:12 +0200 Subject: fixed MinGW SDL stdio redirection issue instead of trying to reopen stdout and stderr, we ensure that stdio redirection is not initialized in the first place. * the workaround code could be in a separate C or C++ file but that would require conditional compilation and linking and therefore a new Automake conditional --- src/main.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index c933a10..1f15c6e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -190,12 +190,6 @@ main(int argc, char **argv) port, sdl_flags, show_cursor, width, height, bpp, framerate); -#ifdef __WIN32__ - /* disable SDL's stdio redirect */ - freopen("CON", "w", stdout); - freopen("CON", "w", stderr); -#endif - if (SDL_Init(SDL_INIT_VIDEO)) { SDL_ERROR("SDL_Init"); return EXIT_FAILURE; @@ -240,3 +234,22 @@ main(int argc, char **argv) /* never reached */ return EXIT_FAILURE; } + +#if defined(__WIN32__) && defined(main) +#undef main +/* + * Define a main() symbol, so that libmingw32 won't define it and libSDLmain's + * WinMain() is not called since that would initiate stdio redirection. + * Instead we call libSDLmain's console_main() which in turn calls + * the main() defined above which was renamed to SDL_main by SDL CFLAGS. + */ + +extern "C" int console_main(int argc, char *argv[]); + +extern "C" int +main(int argc, char *argv[]) +{ + return console_main(argc, argv); +} + +#endif -- cgit v1.2.3