Skip to content

sketchPath is different on OSX then Windows #808

Open
@processing-bot

Description

@processing-bot

Created by: clankill3r

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcorehas attachmentAttachment was not transfered from GitLab

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions