From bf6a6f6dbb65dff4ca5bc8d7b461edaa18d0b62b Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Wed, 19 Aug 2015 09:53:24 -0400 Subject: [PATCH] add additional error-checking and workarounds for #3624 --- app/src/processing/app/Base.java | 12 ++--- app/src/processing/app/Messages.java | 2 +- .../app/platform/WindowsPlatform.java | 45 +++++++++++++++++-- todo.txt | 5 ++- 4 files changed, 52 insertions(+), 12 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index cb6690ab1..735289773 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -111,7 +111,7 @@ public class Base { try { createAndShowGUI(args); } catch (Throwable t) { - Messages.showBadnessTrace("It was not meant to be", + Messages.showTrace("It was not meant to be", "A serious problem happened during startup. Please report:\n" + "http://github.com/processing/processing/issues/new", t, true); } @@ -209,7 +209,7 @@ public class Base { try { new Welcome(base, prompt); } catch (IOException e) { - Messages.showBadnessTrace("Unwelcoming", + Messages.showTrace("Unwelcoming", "Please report this error to\n" + "https://github.com/processing/processing/issues", e, false); } @@ -224,7 +224,7 @@ public class Base { // show this one so that it's not truncated in the error window. t = t.getCause(); } - Messages.showBadnessTrace("We're off on the wrong foot", + Messages.showTrace("We're off on the wrong foot", "An error occurred during startup.", t, true); } Messages.log("done creating base..."); //$NON-NLS-1$ @@ -915,11 +915,11 @@ public class Base { "Try updating the Mode or contact its author for a new version.", nsme); } catch (Throwable t) { if (nextMode.equals(getDefaultMode())) { - Messages.showBadnessTrace("Serious Problem", + Messages.showTrace("Serious Problem", "An unexpected, unknown, and unrecoverable error occurred\n" + "while opening a new editor window. Please report this.", t, true); } else { - Messages.showBadnessTrace("Mode Problems", + Messages.showTrace("Mode Problems", "A nasty error occurred while trying to use " + nextMode.getTitle() + ".\n" + "It may not be compatible with this version of Processing.\n" + "Try updating the Mode or contact its author for a new version.", t, false); @@ -943,7 +943,7 @@ public class Base { */ } catch (Throwable t) { - Messages.showBadnessTrace("Terrible News", + Messages.showTrace("Terrible News", "A serious error occurred while " + "trying to create a new editor window.", t, nextMode == getDefaultMode()); // quit if default diff --git a/app/src/processing/app/Messages.java b/app/src/processing/app/Messages.java index 3be3f312e..07e1a6247 100644 --- a/app/src/processing/app/Messages.java +++ b/app/src/processing/app/Messages.java @@ -155,7 +155,7 @@ public class Messages { /** * Testing a new warning window that includes the stack trace. */ - static void showBadnessTrace(String title, String message, + static public void showTrace(String title, String message, Throwable t, boolean fatal) { if (title == null) title = fatal ? "Error" : "Warning"; diff --git a/app/src/processing/app/platform/WindowsPlatform.java b/app/src/processing/app/platform/WindowsPlatform.java index c3731bc92..cb336dc39 100644 --- a/app/src/processing/app/platform/WindowsPlatform.java +++ b/app/src/processing/app/platform/WindowsPlatform.java @@ -501,7 +501,46 @@ public class WindowsPlatform extends DefaultPlatform { // Code partially thanks to Richard Quirk from: // http://quirkygba.blogspot.com/2009/11/setting-environment-variables-in-java.html - static WinLibC clib = (WinLibC) Native.loadLibrary("msvcrt", WinLibC.class); + static WinLibC clib; + + + static WinLibC getLibC() { + if (clib == null) { + try { + clib = (WinLibC) Native.loadLibrary("msvcrt", WinLibC.class); + } catch (UnsatisfiedLinkError ule) { + // Might be a problem with file encoding, use a default directory + // https://github.com/processing/processing/issues/3624 + File ctmp = new File("C:\\TEMP"); // kick it old school + if (ctmp.exists() || ctmp.mkdirs()) { + try { + File jnaTmp = File.createTempFile("processing", "jna", ctmp); + if (jnaTmp.mkdirs()) { + jnaTmp.deleteOnExit(); // clean up when we're done + System.setProperty("jna.tmpdir", jnaTmp.getAbsolutePath()); + try { + clib = (WinLibC) Native.loadLibrary("msvcrt", WinLibC.class); + } catch (UnsatisfiedLinkError ulf) { + Messages.showTrace("No luck with JNA", + "After several attempts, JNA could not be loaded. Please report:\n" + + "http://github.com/processing/processing/issues/new", ulf, true); + } + } + } catch (IOException e) { + Messages.showTrace("Could not create temp directory", + "JNA could not be loaded properly. Please report:\n" + + "http://github.com/processing/processing/issues/new", e, true); + } + } else { + Messages.showError("Could not create temp directory", + "JNA could not be loaded into C:\\TEMP. Please report:\n" + + "http://github.com/processing/processing/issues/new", null); + } + } + } + return clib; + } + public interface WinLibC extends Library { //WinLibC INSTANCE = (WinLibC) Native.loadLibrary("msvcrt", WinLibC.class); @@ -512,7 +551,7 @@ public class WindowsPlatform extends DefaultPlatform { public void setenv(String variable, String value) { //WinLibC clib = WinLibC.INSTANCE; - clib._putenv(variable + "=" + value); + getLibC()._putenv(variable + "=" + value); } @@ -525,7 +564,7 @@ public class WindowsPlatform extends DefaultPlatform { //WinLibC clib = WinLibC.INSTANCE; //clib._putenv(variable + "="); //return 0; - return clib._putenv(variable + "="); + return getLibC()._putenv(variable + "="); } diff --git a/todo.txt b/todo.txt index 595a00f7d..92f08ddb6 100644 --- a/todo.txt +++ b/todo.txt @@ -11,8 +11,9 @@ X https://github.com/processing/processing/issues/707 X https://github.com/processing/processing/pull/3660 gsoc -_ Foundation libraries disapear from CM after restart -_ https://github.com/processing/processing/issues/3659 +X Foundation libraries disapear from CM after restart +X https://github.com/processing/processing/issues/3659 +X https://github.com/processing/processing/pull/3663 earlier X modify build to insert these after antlr run: