processing4 icon indicating copy to clipboard operation
processing4 copied to clipboard

sketchPath is different on OSX then Windows

Open clankill3r opened this issue 2 years ago • 2 comments

Processing 4.3 (and prior) Windows 10

When working outside the IDE it's common to put the libraries in a lib folder like: (even when not using processing this is common)

sketchPath

The above works fine on OSX, but on windows it does not work. The reason it breaks on windows: https://github.com/benfry/processing4/blob/main/core/src/processing/core/PApplet.java#L7186

        if (jarPath.contains("/lib/")) {
          // Windows or Linux, back up a directory to get the executable
          folder = new File(jarPath, "../..").getCanonicalPath();
        }

It is assumed that core.jar is directly in the lib folder, in the above case sketchPath becomes rootOfProject/lib and dataPath becomes rootOfProject/lib/data.

For now I use this in my sketch:

    public void fixSketchPath() {
        try {
            Field sketchPathField = PApplet.class.getDeclaredField("sketchPath");
            sketchPathField.setAccessible(true);

            String sketchPath = (String) sketchPathField.get(this);

            if (sketchPath.contains("\\lib")) {
                int libIndex = sketchPath.indexOf("\\lib");
                sketchPath = sketchPath.substring(0, libIndex);
            }

            sketchPathField.set(this, sketchPath);

        } catch (NoSuchFieldException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }

But this is of course more a work around then a fix.

clankill3r avatar Dec 02 '23 11:12 clankill3r

@clankill3r I would like to work on this. May I?

aayushk9 avatar Dec 03 '23 12:12 aayushk9

I won't stop you :)

clankill3r avatar Dec 05 '23 08:12 clankill3r