Crash on selectInput() and loadStrings()?
in
Programming Questions
•
1 year ago
I'm trying to load a saved preferences file which resets a number of parameters. It works beautifully when I select a valid file, but crashes pretty consistently (not all the time) if I abort the file-select process, or if I choose an invalid file.
I'm using P5 1.5.1, OSX 10.6.8.
The condensed code below reproduces the problem on my system. Can anyone else confirm this behavior? Spot the problem, suggest a fix?
TIA,
RA
I'm using P5 1.5.1, OSX 10.6.8.
The condensed code below reproduces the problem on my system. Can anyone else confirm this behavior? Spot the problem, suggest a fix?
TIA,
RA
- int x = 0; int y;
- void draw() { // Proxy draw stuff here for debugging feedback.
- noStroke();
- rect(0, 0, width, height);
- stroke(0);
- y = height/2;
- ellipse(x, y, 4, 4);
- x++;
- x = x % width;
- }
- void keyPressed() {
- // Load Preferences.
- if (key == RETURN || key == ENTER) {
- String getPrefs = selectInput();
- if (getPrefs != null) {
- String[] validatesPMT = match(getPrefs, "pmt_"); // Validate file prefix.
- String[] validatesTXT = match(getPrefs, ".txt"); // Validate file suffix.
- if (validatesPMT != null && validatesTXT != null) {
- String[] readPrefs = loadStrings(getPrefs);
- int foo = int(readPrefs[0]);
- // array [etc.]
- }
- else println("Please make sure the file you are selecting begins with \"pmt_\" and ends with \".txt.\"");
- }
- else println("No file was selected.");
- }
- }
1