Skip to content

Commit b3763a8

Browse files
committed
prevent infinite "sketch disappeared" warnings (fixes #4805)
1 parent 07dfee2 commit b3763a8

2 files changed

Lines changed: 32 additions & 23 deletions

File tree

app/src/processing/app/Sketch.java

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
import java.beans.PropertyChangeListener;
4141
import java.io.*;
4242
import java.util.ArrayList;
43+
import java.util.HashSet;
4344
import java.util.List;
45+
import java.util.Set;
4446
import java.util.concurrent.atomic.AtomicBoolean;
4547

4648
import javax.swing.*;
@@ -1497,29 +1499,36 @@ public void prepareBuild(File targetFolder) throws SketchException {
14971499
*/
14981500

14991501

1502+
private Set<File> existenceWarnings = new HashSet<>();
1503+
15001504
/**
1501-
* Make sure the sketch hasn't been moved or deleted by some
1502-
* nefarious user. If they did, try to re-create it and save.
1503-
* Only checks to see if the main folder is still around,
1504-
* but not its contents.
1505+
* Make sure the sketch hasn't been moved or deleted by a nefarious user.
1506+
* If they did, try to re-create it and save. Only checks whether the
1507+
* main folder is still around, but not its contents.
15051508
*/
15061509
public void ensureExistence() {
15071510
if (!folder.exists()) {
1508-
// Disaster recovery, try to salvage what's there already.
1509-
Messages.showWarning(Language.text("ensure_exist.messages.missing_sketch"),
1510-
Language.text("ensure_exist.messages.missing_sketch.description"));
1511-
try {
1512-
folder.mkdirs();
1513-
modified = true;
1511+
// Avoid an infinite loop if we've already warned about this
1512+
// https://github.com/processing/processing/issues/4805
1513+
if (!existenceWarnings.contains(folder)) {
1514+
existenceWarnings.add(folder);
1515+
1516+
// Disaster recovery, try to salvage what's there already.
1517+
Messages.showWarning(Language.text("ensure_exist.messages.missing_sketch"),
1518+
Language.text("ensure_exist.messages.missing_sketch.description"));
1519+
try {
1520+
folder.mkdirs();
1521+
modified = true;
1522+
1523+
for (int i = 0; i < codeCount; i++) {
1524+
code[i].save(); // this will force a save
1525+
}
1526+
calcModified();
15141527

1515-
for (int i = 0; i < codeCount; i++) {
1516-
code[i].save(); // this will force a save
1528+
} catch (Exception e) {
1529+
Messages.showWarning(Language.text("ensure_exist.messages.unrecoverable"),
1530+
Language.text("ensure_exist.messages.unrecoverable.description"), e);
15171531
}
1518-
calcModified();
1519-
1520-
} catch (Exception e) {
1521-
Messages.showWarning(Language.text("ensure_exist.messages.unrecoverable"),
1522-
Language.text("ensure_exist.messages.unrecoverable.description"), e);
15231532
}
15241533
}
15251534
}

todo.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ jakub
2222
X Fix sketch exception getting hidden by warning
2323
X https://github.com/processing/processing/pull/5486
2424
X https://github.com/processing/processing/issues/5412
25+
X EventQueue problems with "could not find sketch size" message
26+
X https://github.com/processing/processing/issues/4893
27+
X https://github.com/processing/processing/pull/5708
28+
X https://github.com/processing/processing/issues/5030 (duplicate)
29+
X size(0, 0) just freezes instead of showing an error
30+
X https://github.com/processing/processing/issues/5233 (duplicate)
2531

2632

2733
_ Find in Reference disabled for various keywords (draw, for, if, catch, while)
@@ -38,12 +44,6 @@ _ seen in Eclipse; have to turn on the debugger
3844
_ "Sketch disappeared" infinite pop up dialogs
3945
_ https://github.com/processing/processing/pull/4808
4046
_ https://github.com/processing/processing/issues/4805
41-
_ EventQueue problems with "could not find sketch size" message
42-
_ https://github.com/processing/processing/issues/4893
43-
X https://github.com/processing/processing/pull/5708
44-
X https://github.com/processing/processing/issues/5030 (duplicate)
45-
_ size(0, 0) just freezes instead of showing an error
46-
X https://github.com/processing/processing/issues/5233 (duplicate)
4747

4848

4949
manager

0 commit comments

Comments
 (0)