Export Application Shows Blank Canvas

Hi, I’ve got an app I’ve made over a few months that works fine when launched from Processing, but exporting to Apple Silicone app fails.

I’ve googled this a lot but nothing I’ve found has solved this.

Here’s what happens when I try to launch the exported app:

Here are my settings:

How can I get this working?

Thanks,

Mike

After more googling, I tried right-clicking the app icon and getting the contents. Then I navigated to the Java folder and double-clicked the terminal app icon.

It again launched to a gray screen. But then I looked at the terminal info, and it said it was generating a null-pointer error as it was not able to find a text file I was referencing. Which is odd, because I do not have that issue when using the app from Processing.

In any case, moving the text file to the data folder now allows it to launch correctly!

However, now in processing the original function that needed that text file isn’t working.

So, a victory for the original request, but a headache now to figure out the rest.

Thanks for reading, hope this helps someone.

Mike

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

There is no bug in the Processing Export function, the issue is the directory path to your options file. It will be different for the sketch and exported application.

This should work in both the sketch (pre-export) and the exported app

optString = loadStrings(dataPath("") +"/options.txt");

dataPath("") returns the absolute path to the data folder.

All file resources e.g. text, graphics, sounds, fonts etc. that are required by the exported app should be placed in the data folder. I see you have discovered this for yourself. :grin:

3 Likes

Are you rescuing me even if it’s not your lib?

Thank you so much - I’ve spent a couple frustrating hours on this.

Your solution works perfectly. Shocker :slight_smile:

I’m not clear on why simply referencing “data/options.txt” doesn’t work? I don’t have to use the special absolute path reference you shared with any of the other resources I’ve got, for tons of images for example…

In any case, this is absolutely wonderful. Thank you kind sir :smiling_face_with_three_hearts:

It doesn’t work because it is the path relative to the sketch folder. Once the sketch is exported the relative path would have to be from the executable file but that is not the same. The dataPath("") method returns the absolute path to the data folder irrespective of sketch or executable whichever is being used.

So in a Processing sketch the lines

optString = loadStrings(dataPath("") +"/options.txt");
and
optString = loadStrings("data/options.txt");

are synonymous but not for the exported app.

2 Likes

Thank you so much Peter. As per usual!!

Also, it’s interesting that we don’t have to do this for images. I just plop them in the data folder and refer to them and they export into a compiled app without complaint.

But you got it working for me! So thanks again!!

Mike

We can also pass the string as an argument for function dataPath() w/o the slash /:
optString = loadStrings(dataPath("options.txt"));

When running from the PDE (Processing’s IDE), by default, all loading functions check both the sketch’s root folder and then its subfolder “data/” for the file.

Therefore, we don’t need to use dataPath() for loading operations.

However, all saving functions save the file to the sketch’s root folder.

If we wish to force it into subfolder “data/”, we need to use dataPath() to create the path string:
saveStrings(dataPath("options.txt"), optString);

4 Likes

@GoToLoop that’s wonderful sharing! Thank you!!

Mike