Skip to content

Commit 0ec0db4

Browse files
committed
Fix Windows exit code -1073741819: always copy DLLs next to binary, null-check glfwCreateWindow
- checkWindowsDLLs: copy glfw3.dll, glew32.dll, libgcc_s_seh-1.dll, libstdc++-6.dll, libwinpthread-1.dll next to the compiled binary on every build, not just after a pacman install. Previously the DLLs existed in C:\msys64\mingw64\bin but Windows couldn't find them at runtime unless they were next to the exe or on PATH -- causing 0xC0000005 (access violation) immediately on sketch launch. - Processing.cpp: null-check glfwCreateWindow() return value. If window creation fails (old GPU driver, missing OpenGL 3.3 support), show a MessageBoxA with driver update links instead of crashing with a null pointer dereference. Previously the code passed null directly to glfwSetWindowRefreshCallback() causing 0xC0000005.
1 parent 17ed6af commit 0ec0db4

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

src/Processing.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3053,6 +3053,24 @@ void PApplet::run(){
30533053
glfwWindowHint(GLFW_SAMPLES,4); // 4x MSAA for crisp P3D rendering; 2D noSmooth() disables at runtime
30543054
glfwWindowHint(GLFW_STENCIL_BITS,8); // needed for concave shape fill
30553055
gWindow=glfwCreateWindow(winWidth,winHeight,g_sketchName.c_str(),nullptr,nullptr);
3056+
if(!gWindow){
3057+
const char* err=nullptr; glfwGetError(&err);
3058+
fprintf(stderr,"[ERR] glfwCreateWindow() failed: %s\n", err?err:"unknown");
3059+
#ifdef _WIN32
3060+
MessageBoxA(NULL,
3061+
"Failed to create OpenGL window.\n\n"
3062+
"This usually means:\n"
3063+
" - Your GPU driver does not support OpenGL 3.3\n"
3064+
" - glfw3.dll or glew32.dll is missing next to the sketch exe\n\n"
3065+
"Try updating your GPU drivers.\n"
3066+
"Intel: https://www.intel.com/content/www/us/en/download-center/home.html\n"
3067+
"AMD: https://www.amd.com/en/support\n"
3068+
"NVIDIA: https://www.nvidia.com/drivers",
3069+
"processing-cpp: Window Creation Failed", MB_OK|MB_ICONERROR);
3070+
#endif
3071+
glfwTerminate();
3072+
return;
3073+
}
30563074
// Prevent freeze when dragging title bar on Windows
30573075
glfwSetWindowRefreshCallback(gWindow,[](GLFWwindow* w){
30583076
// Originally just glClear()+swap "to prevent freeze when dragging the

src/java/CppBuild.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,13 +492,35 @@ private boolean windowsLibsNowPresent(java.util.List<String> searchDirs, String[
492492

493493
private void checkWindowsDLLs(RunnerListener listener, File binary) throws Exception {
494494
String[] required = { "glfw3.dll", "glew32.dll" };
495+
String[] allDlls = { "glfw3.dll", "glew32.dll",
496+
"libgcc_s_seh-1.dll", "libstdc++-6.dll", "libwinpthread-1.dll" };
497+
String[] msysDirs = { "C:\\msys64\\mingw64\\bin", "C:\\msys2\\mingw64\\bin" };
498+
495499
java.util.List<String> searchDirs = new java.util.ArrayList<>();
496500
searchDirs.add(binary.getParent());
497-
searchDirs.add("C:\\msys64\\mingw64\\bin");
498-
searchDirs.add("C:\\msys2\\mingw64\\bin");
501+
for (String d : msysDirs) searchDirs.add(d);
499502
String path = System.getenv("PATH");
500503
if (path != null) for (String p : path.split(";")) searchDirs.add(p);
501504

505+
// Always copy all required DLLs next to the binary so the sketch can
506+
// find them at runtime without MSYS2 on PATH. This is the root cause of
507+
// exit code -1073741819 (0xC0000005) on fresh Windows installs: the DLLs
508+
// exist in C:\msys64\mingw64in but Windows can't find them at runtime
509+
// unless they're next to the exe or on PATH. Copy unconditionally.
510+
for (String dll : allDlls) {
511+
File dest = new File(binary.getParent(), dll);
512+
if (dest.exists()) continue; // already copied from a previous run
513+
for (String dir : msysDirs) {
514+
File src2 = new File(dir, dll);
515+
if (src2.exists()) {
516+
try { java.nio.file.Files.copy(src2.toPath(), dest.toPath(),
517+
java.nio.file.StandardCopyOption.REPLACE_EXISTING); }
518+
catch (Exception ignored) {}
519+
break;
520+
}
521+
}
522+
}
523+
502524
java.util.List<String> missing = new java.util.ArrayList<>();
503525
outer:
504526
for (String dll : required) {

0 commit comments

Comments
 (0)