Processing can find the data folder in Windows 11 but not in Linux or Mac

I will do so tomorrow by describing the problem in more detail and asking my colleagues exactly which versions of OS and Processing they have.

The only thing that changed from the original project I uploaded was in the Main.pde file, so I will make sure to document the changes in the solution thoroughly.

Thank you!!

2 Likes

Use constant { ARGS_SKETCH_FOLDER + sketchPath(), "" } array as the 1st argument for runSketch() to instantiate extra PApplet subclasses:

1 Like

What advantage does:

PApplet.runSketch(new String[]{ ARGS_SKETCH_FOLDER + sketchPath(), "" },this);

have over:

PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);

?

Hello @GoToLoop,

Cool beans! Adding this to my Processing notes.

I had to add an = sign for this to work with sketchPath() in layer in your code (subsketch_0 in my code):

final String[] switches = { ARGS_SKETCH_FOLDER + "=" + sketchPath(), "" };

The sketchPath() is the same for each now:

This is what the output is without passing the ARGS_SKETCH_FOLDER:

Thanks for sharing!

:)

If you’re going to stick an “=“ sign in there why not just use:

PApplet.runSketch(new String[]{ sketchPath(), "" },this);

That works too on my mac.

It’s expecting the name of the class that extends PApplet and that’s what this.getClass().getSimpleName() does. If the name of your class is “TestWindow“ and you use

 PApplet.runSketch(new String[]{"TestWindow"},this);

that will work too (on a mac, not tested on other platforms).

Actually you can get by with only this:

PApplet.runSketch(new String[]{""},this);

In summary, using sketchPath() in a PApplet returns only a forwardslash on my system and is worthless. I’m sticking with my last snippet unless someone has a compelling reason to change.

If you want to confirm my findings here is a test app that you may run:

class TestWindow extends PApplet {
  TestWindow () {
  PApplet.runSketch(new String[]{""},this);
  }

  void settings() {
    size(200, 200);
  }

  void setup() {
    background(106);
    println("className = ",this.getClass().getSimpleName() );
    println("ARGS_SKETCH_FOLDER =",ARGS_SKETCH_FOLDER);
    println("sketchPath = ",sketchPath());   
    printArray(new String[]{ ARGS_SKETCH_FOLDER + sketchPath(), ""});
    println("dataPath = ",dataPath(""));
  }
}

TestWindow testWindow;

void setup() {
  surface.setVisible(false);
  testWindow = new TestWindow();
}

Mac Output:

Note that dataPath() doesn’t work inside of a PApplet either which is why the OP’s Mac friend couldn’t use loadImage() as expected.

Hello @svan,

The context of my previous response was to this topic and the code provided:

Environment is Windows 10 with Processing 4.4.10 for this post.

I modified the code you provided here for the context above:

TestWindow testWindow;

void setup() {
  surface.setVisible(false);
  testWindow = new TestWindow();
  final String[] switches = { ARGS_SKETCH_FOLDER + "=" + sketchPath(), "" }; // With sketchPath() ... An = sign is required!
  //final String[] switches = { "" }; // Added an = sign   // Without sketchPath 
  
  println("Main sketch:");
  println("className = ", this.getClass().getSimpleName() );
  println("ARGS_SKETCH_FOLDER =", ARGS_SKETCH_FOLDER);
  println("sketchPath = ", sketchPath()); 
  printArray(switches);
  //printArray(new String[]{ ARGS_SKETCH_FOLDER + sketchPath(), ""}); // You can see that this is missing an = sign
  println("dataPath = ", dataPath(""));
  println();
  
  runSketch(switches, testWindow = new TestWindow());
  }

class TestWindow extends PApplet {
  TestWindow () { 
  //PApplet.runSketch(new String[]{""},this);  
  }

  void settings() {
    size(200, 200);
  }

  void setup() {
    background(106);
    println("testWindow:");
    println("className = ", this.getClass().getSimpleName() );
    println("ARGS_SKETCH_FOLDER =", ARGS_SKETCH_FOLDER);
    println("sketchPath = ", sketchPath());
    println(ARGS_SKETCH_FOLDER + "=" + sketchPath()); // The = sign added that is required
    printArray(new String[]{ ARGS_SKETCH_FOLDER + sketchPath(), ""}); // You can see that this is missing an = sign
    println("dataPath = ", dataPath(""));
  }
}

Output PASSING the sketchPath():

Main sketch:
className =  Testing
ARGS_SKETCH_FOLDER = --sketch-path
sketchPath =  D:\Users\GLV\Documents\Processing\PF_Testing
[0] "--sketch-path=D:\Users\GLV\Documents\Processing\PF_Testing"
[1] ""
dataPath =  D:\Users\GLV\Documents\Processing\PF_Testing\data

testWindow:
className =  TestWindow
ARGS_SKETCH_FOLDER = --sketch-path
sketchPath =  D:\Users\GLV\Documents\Processing\PF_Testing
--sketch-path=D:\Users\GLV\Documents\Processing\PF_Testing
[0] "--sketch-pathD:\Users\GLV\Documents\Processing\PF_Testing"
[1] ""
dataPath =  D:\Users\GLV\Documents\Processing\PF_Testing\data

Output NOT PASSING the sketchPath():

Main sketch:
className =  Testing
ARGS_SKETCH_FOLDER = --sketch-path
sketchPath =  D:\Users\GLV\Documents\Processing\PF_Testing
[0] ""
dataPath =  D:\Users\GLV\Documents\Processing\PF_Testing\data

testWindow:
className =  TestWindow
ARGS_SKETCH_FOLDER = --sketch-path
sketchPath =  D:\Program_Portable\Processing-4.4.10
--sketch-path=D:\Program_Portable\Processing-4.4.10
[0] "--sketch-pathD:\Program_Portable\Processing-4.4.10"
[1] ""
dataPath =  D:\Program_Portable\Processing-4.4.10\data

This is the output on W10 with Processing 4.4.10 of your demo:

One more method and my last one:

Code hidden here!
/*
 * Launcher for Multi-Renderer PApplets
 *
 * Author: glv
 * Date: 2025-11-04
 *
 */

// Renderer Applets:
renderApp_0 app_0; // JAVA2D

void settings() {
  size(200, 200);
}

void setup() {
  surface.setTitle("Launcher");
  println("Main sketch:", sketchPath());

  // app_0 Lambda Thread (active)
  app_0 = new renderApp_0();
  final String[] switches = { ARGS_SKETCH_FOLDER + "=" + sketchPath(), // With sketchPath()
                              "renderapp_0" };
  Thread thread_0 = new Thread(() -> PApplet.runSketch(switches, app_0));
  //Thread thread_0 = new Thread(() -> PApplet.runSketch(new String[]{"renderapp_0"}, app_0)); //// Without sketchPath()
  thread_0.start();
}

void draw() {
  background(255);
  translate(width/2, height/2);

  fill(0);
  textSize(24);
  textAlign(CENTER, CENTER);
  text("Launcher JAVA2D", 0, 0);
}

// JAVA2D
class renderApp_0 extends PApplet {
  void settings() {
    size(200, 200);
  }

  void setup() {
    surface.setTitle("Launcher");
    println("RenderApp_0:", sketchPath());
  }

  void draw() {
    background(255);
    translate(width/2, height/2);

    fill(0);
    textSize(24);
    textAlign(CENTER, CENTER);
    text("JAVA2D", 0, 0);
  }
}

:)

Indeed, that was a very old example which I had forgotten to include an '=' character, which is required for the runSketch()'s switch/case block parser:

So this is the fixed line:
final String[] switches = { ARGS_SKETCH_FOLDER + '=' + sketchPath(), "" };

1 Like

Your output on Windows is different from a Mac; there appears to be platform differences! Does my demo run with an empty string, ie do you see the “Test Window“? Here’s what I see on Windows 11 with an empty string in the array:

Runs on Linux(popOS) with empty string also and there is output for sketchPath() and dataPath() similar to Windows.

I’m curious why you would want to use the extra code when something simple works?

PApplet.runSketch() just wants a String array and it apparently doesn’t really care what the String is; even an empty one will work.

This is the text in your image:

ARGS_SKETCH_FOLDER = --sketch-path
sketchPath = /snap/processing/10/opt/processing/lib/app/resources/core
[0] "--sketch-path/snap/processing/10/opt/processing/lib/app/resources/core"
[1] ""
dataPath = /snap/processing/10/opt/processing/lib/app/resources/core/data

This should have an = sign if used for Windows and passing the argument:

[0] "--sketch-path=/snap/processing/10/opt/processing/lib/app/resources/core"

We do not seem to be on the same page in this discussion.

Each OS seems to have its nuances and I am getting lost in the quagmire.

Curiosity is the beginning of all wisdom .” - Quote by Françoise Sagan.

This is the objective I have been working towards:

This code launches a new TestWindow instance and correctly passes the ARGS_SKETCH_FOLDER argument to ensure that sketchPath() and dataPath() resolve properly within the new PApplet.

This code achieves that objective on Windows 10 and Processing 4.4.10 :

// Main sketch
TestWindow testWindow;

void setup() {
  // The argument array MUST contain the equals sign to work:
  final String[] switches = { ARGS_SKETCH_FOLDER + "=" + sketchPath(), "" }; 
  //final String[] switches = { "" }; 
  
  println("--- Main Sketch ---");
  println("Main sketchPath:"); 
  println(sketchPath());
  println("Arguments Passed:");
  printArray(switches);
  
  // Launch the PApplet instance
  runSketch(switches, testWindow = new TestWindow());
}

void draw() {
  exit();
}

// Separate PApplet class
class TestWindow extends PApplet {
  void settings() {
    size(200, 200);
  }

  void setup() {
    background(100);
    println("\n--- TestWindow PApplet ---");
    
    // 'testWindow' (lowercase) refers to the launched instance:
    println("testWindow sketchPath: ");
    println(sketchPath()); 
    println("testWindow dataPath:"); 
    println(dataPath(""));
  }
  
  void draw() {}
}

I also passed a global variable in earlier examples.

This was certainly an engaging topic, and all good things must come to an end… my participation will have to end here.

@ffernandaffranco Thanks for the topic!

Have fun!

:)

I concede that { ARGS_SKETCH_FOLDER + “=” + sketchPath(), “” }; is necessary to pass sketchPath() from a Processing app to the PApplet; it also allows loadImage(“myImg.png“) to work correctly on a Mac after doing that. What I can’t figure out is how the dataPath(““) got passed.

1 Like

Functions dataPath() & dataFile() rely on field sketchPath + “data”:

1 Like

Thanks. I finally figured that out; once you’ve got sketchPath() it’s pretty easy to tack on ‘/data‘. This thread has been instructive in a number of ways: 1) There are differences in the platforms 2) At least on a Mac, PApplet doesn’t know its sketchPath()/dataPath() 3) There is a way to pass sketchPath() in from a base Processing app or alternatively use the full path to the data folder for a call such as loadImage() which depends on it.

1 Like