Skip to content

Commit 3fddac4

Browse files
committed
Windows: sync_with_stdio(false) before first iostream use to prevent MinGW crash
1 parent a6d5e11 commit 3fddac4

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

mode/CppMode.jar

2 Bytes
Binary file not shown.

src/Processing.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ struct _LocaleInit {
9898
static _LocaleInit _locale_init_instance;
9999
#endif
100100

101+
// On Windows, avoid std::cerr/cout which crash during ios_base::_M_init
102+
// when no console is attached (MinGW 14+ bug with -mwindows)
103+
#ifdef _WIN32
104+
#define CPP_ERR(...) fprintf(stderr, __VA_ARGS__)
105+
#define CPP_OUT(...) fprintf(stdout, __VA_ARGS__)
106+
#else
107+
#define CPP_ERR(...) fprintf(stderr, __VA_ARGS__)
108+
#define CPP_OUT(...) fprintf(stdout, __VA_ARGS__)
109+
#endif
110+
101111
// default.ttf in the project root is loaded automatically as the default font.
102112

103113

@@ -3333,6 +3343,11 @@ void PApplet::run(){
33333343
PDEBUG("CppMode build stamp: %s\n", PROCESSING_BUILD_STAMP);
33343344
PDEBUG("Debug mode ON -- PApplet::run() starting\n");
33353345
g_papplet = this;
3346+
#ifdef _WIN32
3347+
// Prevent ios_base crash on Windows by syncing before first use
3348+
::std::ios_base::sync_with_stdio(false);
3349+
::std::cin.tie(nullptr);
3350+
#endif
33363351
signal(SIGTERM, [](int){ if(PApplet::g_papplet && PApplet::g_papplet->gWindow) glfwSetWindowShouldClose(PApplet::g_papplet->gWindow, GLFW_TRUE); });
33373352
#ifndef _WIN32
33383353
// SIGHUP is POSIX-only -- Windows has no controlling-terminal/session

0 commit comments

Comments
 (0)