From fc6b8385bd534fec4ec3f4f42830b447f16ffdc6 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Fri, 18 Jan 2019 11:19:28 -0800 Subject: [PATCH] prevent infinite "sketch disappeared" warnings (fixes #4805) --- app/src/processing/app/Sketch.java | 43 ++++++++++++++++++------------ todo.txt | 12 ++++----- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index 40a3d7fb2..15882dfb5 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -40,7 +40,9 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.*; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; import javax.swing.*; @@ -1497,29 +1499,36 @@ public class Sketch { */ + private Set existenceWarnings = new HashSet<>(); + /** - * Make sure the sketch hasn't been moved or deleted by some - * nefarious user. If they did, try to re-create it and save. - * Only checks to see if the main folder is still around, - * but not its contents. + * Make sure the sketch hasn't been moved or deleted by a nefarious user. + * If they did, try to re-create it and save. Only checks whether the + * main folder is still around, but not its contents. */ public void ensureExistence() { if (!folder.exists()) { - // Disaster recovery, try to salvage what's there already. - Messages.showWarning(Language.text("ensure_exist.messages.missing_sketch"), - Language.text("ensure_exist.messages.missing_sketch.description")); - try { - folder.mkdirs(); - modified = true; + // Avoid an infinite loop if we've already warned about this + // https://github.com/processing/processing/issues/4805 + if (!existenceWarnings.contains(folder)) { + existenceWarnings.add(folder); - for (int i = 0; i < codeCount; i++) { - code[i].save(); // this will force a save + // Disaster recovery, try to salvage what's there already. + Messages.showWarning(Language.text("ensure_exist.messages.missing_sketch"), + Language.text("ensure_exist.messages.missing_sketch.description")); + try { + folder.mkdirs(); + modified = true; + + for (int i = 0; i < codeCount; i++) { + code[i].save(); // this will force a save + } + calcModified(); + + } catch (Exception e) { + Messages.showWarning(Language.text("ensure_exist.messages.unrecoverable"), + Language.text("ensure_exist.messages.unrecoverable.description"), e); } - calcModified(); - - } catch (Exception e) { - Messages.showWarning(Language.text("ensure_exist.messages.unrecoverable"), - Language.text("ensure_exist.messages.unrecoverable.description"), e); } } } diff --git a/todo.txt b/todo.txt index 6b47d382e..a1f4d2dc0 100755 --- a/todo.txt +++ b/todo.txt @@ -22,6 +22,12 @@ jakub X Fix sketch exception getting hidden by warning X https://github.com/processing/processing/pull/5486 X https://github.com/processing/processing/issues/5412 +X EventQueue problems with "could not find sketch size" message +X https://github.com/processing/processing/issues/4893 +X https://github.com/processing/processing/pull/5708 +X https://github.com/processing/processing/issues/5030 (duplicate) +X size(0, 0) just freezes instead of showing an error +X https://github.com/processing/processing/issues/5233 (duplicate) _ 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 _ "Sketch disappeared" infinite pop up dialogs _ https://github.com/processing/processing/pull/4808 _ https://github.com/processing/processing/issues/4805 -_ EventQueue problems with "could not find sketch size" message -_ https://github.com/processing/processing/issues/4893 -X https://github.com/processing/processing/pull/5708 -X https://github.com/processing/processing/issues/5030 (duplicate) -_ size(0, 0) just freezes instead of showing an error -X https://github.com/processing/processing/issues/5233 (duplicate) manager