Skip to content

Commit ed04c59

Browse files
committed
checkWindowsDLLs: copy from bundled libs/windows-x64 first, fall back to MSYS2
1 parent 6c832dc commit ed04c59

2 files changed

Lines changed: 14 additions & 17 deletions

File tree

mode/CppMode.jar

93 Bytes
Binary file not shown.

src/java/CppBuild.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ private void checkGppAvailable(RunnerListener listener) throws Exception {
365365
new javax.swing.JLabel(
366366
"<html><b>g++ (C++ compiler) not found.</b><br><br>"
367367
+ "C++ Mode needs g++ to compile sketches.<br>"
368-
+ "GLFW and GLEW are already bundled — no extra downloads needed.<br><br>"
369368
+ "<b>Auto-Install (recommended):</b><br>"
370369
+ "&nbsp;&nbsp;Click <b>Auto-Install</b> to download g++ automatically.<br><br>"
371370
+ "<b>Manual:</b><br>"
@@ -657,22 +656,20 @@ private void checkWindowsDLLs(RunnerListener listener, File binary) throws Excep
657656
String[] allDlls = { "glfw3.dll", "glew32.dll",
658657
"libgcc_s_seh-1.dll", "libstdc++-6.dll", "libwinpthread-1.dll" };
659658
String[] msysDirs = { "C:\\msys64\\mingw64\\bin", "C:\\msys2\\mingw64\\bin" };
660-
659+
File bundledLibsDir = new File(runtimeDir.getParentFile(), "libs/windows-x64");
661660
java.util.List<String> searchDirs = new java.util.ArrayList<>();
662661
searchDirs.add(binary.getParent());
662+
if (bundledLibsDir.exists()) searchDirs.add(bundledLibsDir.getAbsolutePath());
663663
for (String d : msysDirs) searchDirs.add(d);
664664
String path = System.getenv("PATH");
665-
if (path != null) for (String p : path.split(";")) searchDirs.add(p);
666-
667-
// Always copy all required DLLs next to the binary so the sketch can
668-
// find them at runtime without MSYS2 on PATH. This is the root cause of
669-
// exit code -1073741819 (0xC0000005) on fresh Windows installs: the DLLs
670-
// exist in C:\msys64\mingw64in but Windows can't find them at runtime
671-
// unless they're next to the exe or on PATH. Copy unconditionally.
665+
if (path != null) for (String p2 : path.split(";")) searchDirs.add(p2);
666+
java.util.List<String> copyDirs = new java.util.ArrayList<>();
667+
if (bundledLibsDir.exists()) copyDirs.add(bundledLibsDir.getAbsolutePath());
668+
for (String d : msysDirs) copyDirs.add(d);
672669
for (String dll : allDlls) {
673670
File dest = new File(binary.getParent(), dll);
674-
if (dest.exists()) continue; // already copied from a previous run
675-
for (String dir : msysDirs) {
671+
if (dest.exists()) continue;
672+
for (String dir : copyDirs) {
676673
File src2 = new File(dir, dll);
677674
if (src2.exists()) {
678675
try { java.nio.file.Files.copy(src2.toPath(), dest.toPath(),
@@ -682,7 +679,6 @@ private void checkWindowsDLLs(RunnerListener listener, File binary) throws Excep
682679
}
683680
}
684681
}
685-
686682
java.util.List<String> missing = new java.util.ArrayList<>();
687683
outer:
688684
for (String dll : required) {
@@ -3119,13 +3115,14 @@ private List<String> buildCommand(String gpp, File src, File bin, boolean win, b
31193115
boolean lowMemory = freeMemBytes < 512L * 1024 * 1024; // < 512MB JVM headroom
31203116
// Also check system RAM
31213117
try {
3118+
// Use reflection to avoid hard dependency on com.sun.management
31223119
java.lang.management.OperatingSystemMXBean osmx =
3123-
(java.lang.management.OperatingSystemMXBean)
31243120
java.lang.management.ManagementFactory.getOperatingSystemMXBean();
3125-
if (osmx instanceof com.sun.management.OperatingSystemMXBean sunOs) {
3126-
long freeRam = sunOs.getFreeMemorySize();
3127-
if (freeRam < 2L * 1024 * 1024 * 1024) lowMemory = true; // < 2GB free RAM
3128-
}
3121+
java.lang.reflect.Method getFreeMemory =
3122+
osmx.getClass().getMethod("getFreeMemorySize");
3123+
getFreeMemory.setAccessible(true);
3124+
long freeRam = (long) getFreeMemory.invoke(osmx);
3125+
if (freeRam < 2L * 1024 * 1024 * 1024) lowMemory = true;
31293126
} catch (Exception ignored) {}
31303127
if (lowMemory) needsPch = false;
31313128
try {

0 commit comments

Comments
 (0)