Skip to content

Commit b4b3a1d

Browse files
committed
Windows: add bundled libs to PATH when launching sketch
1 parent 298c723 commit b4b3a1d

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

mode/CppMode.jar

293 Bytes
Binary file not shown.

src/java/CppBuild.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -666,15 +666,16 @@ private void checkWindowsDLLs(RunnerListener listener, File binary) throws Excep
666666
for (String dll : allDlls) {
667667
File src2 = new File(bundledDir, dll);
668668
if (!src2.exists()) continue;
669-
// Copy to binary dir (next to the exe)
669+
// Copy next to binary
670670
File dest = new File(binaryDir, dll);
671671
try { java.nio.file.Files.copy(src2.toPath(), dest.toPath(),
672672
java.nio.file.StandardCopyOption.REPLACE_EXISTING);
673673
} catch (Exception e) {
674674
System.err.println("[CppMode] Failed to copy " + dll + ": " + e.getMessage());
675675
}
676-
// Also copy to sketch folder so the sketch can find them when run
677-
File sketchDest = new File(binary.getParentFile().getParentFile(), dll);
676+
// Copy to sketch folder -- CppRunner sets sketch folder as cwd
677+
// so Windows finds DLLs there at runtime
678+
File sketchDest = new File(sketch.getFolder(), dll);
678679
try { java.nio.file.Files.copy(src2.toPath(), sketchDest.toPath(),
679680
java.nio.file.StandardCopyOption.REPLACE_EXISTING);
680681
} catch (Exception ignored) {}

src/java/CppRunner.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ public void launch() {
2525
pb.directory(sketchFolder);
2626
pb.redirectErrorStream(false);
2727
// Pass sketch folder so loadImage/loadStrings find data/ assets
28+
// On Windows, add bundled DLL directory to PATH so the exe finds them at runtime
29+
String osName = System.getProperty("os.name", "").toLowerCase();
30+
if (osName.contains("win") && runtimeDir != null) {
31+
File bundledLibs = new File(runtimeDir.getParentFile(), "libs/windows-x64");
32+
if (bundledLibs.exists()) {
33+
String existingPath = pb.environment().getOrDefault("PATH", "");
34+
pb.environment().put("PATH", bundledLibs.getAbsolutePath() + ";" + existingPath);
35+
}
36+
}
2837
pb.environment().put("PROCESSING_SKETCH_NAME", sketchFolder.getName());
2938
pb.environment().put("PROCESSING_SKETCH_PATH",
3039
sketchFolder.getAbsolutePath().replace('\\', '/'));

0 commit comments

Comments
 (0)