saveStrings()/loadStrings() Causes Gray Screen on Exported Application

Hello,

I have a sketch that works perfectly in Processing (3.5.4) but when I export it as a stand-alone application, people have been reporting a gray screen. I think I’ve narrowed the problem down to the use of saveStrings() and loadStrings(), since the exported app works fine when I rework it to omit those.

Oddly enough though, I’ve had 4 family members test this application out on their computers and have gotten mixed results: The exported app works fine for me on Mac OSX El Capitan but produces a gray screen for my wife’s OSX Catalina. Surprisingly it works fine on my dad’s OSX Snow Leopard, but again produces a gray screen for my Aunt’s OSX Sierra. All have java up to date (and I had bundled java into the export anyway). I don’t have a windows or linux machine handy to test those exports - that may be a whole different can of worms for all I know.

Here’s my goal:
My sketch loads a different PImage each day from 51 images stored in the data folder.

It uses the day() function to check the current day. It then stores that to a .txt file using saveStrings(). Each time the sketch is run it recalls that stored value using loadStrings(), checks it against the current day and increments a counter (whose integer is also stored in that .txt file) if there’s a state change (i.e. it’s not the same day as the last time the sketch was run). That counter is used to select a new image from the 51 images in the data folder each day for the sketch to work with.

Here’s the relevant code from the setup() phase:

  // Check what day it is and load corresponding image 
  int[] savedData = int(loadStrings("dayCounterData.txt")); // load saved day and dayCounter into array
  int savedDay = savedData[0]; // extract saved day into its own variable to compare against current day
  int dayCounter = savedData[1]; // extract saved dayCounter into its own variable to count images
  
  // compare saved day to current day, increment upon state change, and reset if exceeding the max number of images
  if(savedDay != day()){
    dayCounter++;
    if(dayCounter > 51){ 
      dayCounter = 1;
    }
  }

  // compile current day and updated dayCounter back into an array and save to disk
  String[] newData = {str(day()),str(dayCounter)};
  saveStrings("dayCounterData.txt", newData);
  
  // load image that corresponds with the day
  pic=loadImage(dayCounter + ".jpg"); 

My hunch:
I get that loadStrings() and saveStrings() are not symmetrical (which is counterintuitive, but I digress), and that might be causing the problem after the data folder gets compiled into the .jar upon export. Since saveStrings() saves to the sketch folder but loadStrings() reads from the data folder by default, I’ve tried specifying several different paths (as suggested here) for both saveStrings and loadStrings in hopes that it might indicate a different location for the .txt file outside of the data folder, but to no avail.

…But that still doesn’t explain why it does work on my computer.
(To clarify, when I exported at first, it did not work for me until I manually added the .txt file into the export folder after the fact, and it started working fine. But again this is the solution that worked for me and my dad but not my wife or aunt.)

So my questions:

  1. Am I right that load/saveStrings is the culprit, or is all this a red herring and it’s something else entirely?
  2. Is there a better way to increment what image is being used each day that I’m overlooking? (EX. today the sketch should use image 1, tomorrow image 2, and so on until 52 days later it starts over at image 1 again. The exported app must be able to be closed and opened again without losing track)

Other resources
In case it’s helpful, here’s a link to the download page I set up for my exported application so you can see exactly what people are attempting to open:
https://www.valosinprojects.com/Meditations/coronapocalypse/
(I’ve also tried airdropping it between computers in case it was something having to do with the upload/download process itself - no difference)

Thank you so much for any insight, and please pardon any rookie mistakes; I’ve been working with Processing for several years but am by no means a proficient programmer, and this is my first time posting.

Much appreciated, and hope everyone’s safe and healthy during this pandemic!

1 Like