Houston, we still have a problem. I thought I had figured this out, but I had not.
Here is a minimum example that does not work, using loadStrings.
Sketch code:
String[] optString = new String[10];
String strSampleText = "";
PFont f;
public void setup(){
size(300, 300, JAVA2D);
loadSavedPrefs();
f = createFont("Arial",16,true); // Arial, 16 point, anti-aliasing on
}
public void draw(){
background(255);
textFont(f,36);
fill(0);
noStroke();
text(strSampleText,110,150);
}
void loadSavedPrefs(){
try{
optString = loadStrings("options.txt");
}
catch(Exception e){
e.printStackTrace();
}
strSampleText = optString[0];
}//end loadSavedPrefs()
Also, make a text file called “options.txt” and put it in to the sketch folder, per instructions with loadStrings() reference
The options.txt file should simply have the word “Test” on one line, and nothing else in it.
If you run this sketch from processing, it works fine, loading “Test” to the canvas.
Now try exporting for Apple Silicone. If you double click the finished app, you get a blank screen!
If you right-click the app icon and choose Contents, then MacOS, then double click the command line version, it also runs with a blank screen, but you get the following message:
saveStringsTest.app/Contents/MacOS/saveStringsTest ; exit;
The file "options.txt" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
java.lang.NullPointerException: Cannot load from object array because "this.optString" is null
at saveStringsTest.loadSavedPrefs(saveStringsTest.java:41)
at saveStringsTest.setup(saveStringsTest.java:25)
at processing.core.PApplet.handleDraw(PApplet.java:2051)
at processing.awt.PSurfaceAWT$9.callDraw(PSurfaceAWT.java:1386)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:356)
2024-05-31 09:58:12.905 saveStringsTest[45953:1933493] WARNING: Secure coding is not enabled for restorable state! Enable secure coding by implementing NSApplicationDelegate.applicationSupportsSecureRestorableState: and returning YES.
Can anyone try this? You can reproduce it in a second.
FURTHER MORE:
If you now make a “data” folder inside the sketch folder, and COPY the options.txt file there, and update the code thus:
optString = loadStrings("data/options.txt");
This ALSO works fine when running directly from processing, but ALSO FAILS when you export application, with same error.
FINALLY:
Take the previous code, with options copied into the data folder, and also copied into the sketch folder. Right-click the app icon, go to Contents, open Java folder, and paste ANOTHER copy of options.txt into it, you can launch the finished app and it works.
So it’s taking 3 copies of the options.txt file in 3 different folders to make this export correctly.
I thought I was losing my mind! Well, I am. But obvs we don’t want to have to do this silly goofy method!
Seems like a bug with the Processing Export function.
Does anyone have any idea how to get this fixed?
Thanks,
Mike