public Runner(JavaBuild build, RunnerListener listener) throws SketchException { this.listener = listener; // this.sketch = sketch; this.build = build; if (listener instanceof Editor) { this.editor = (Editor) listener; sketchErr = editor.getConsole().getErr(); sketchOut = editor.getConsole().getOut(); } else { sketchErr = System.err; sketchOut = System.out; } // Make sure all the imported libraries will actually run with this setup. int bits = Base.getNativeBits(); for (Library library : build.getImportedLibraries()) { if (!library.supportsArch(PApplet.platform, bits)) { sketchErr.println(library.getName() + " does not run in " + bits + "-bit mode."); int opposite = (bits == 32) ? 64 : 32; if (Base.isMacOS()) { // if (library.supportsArch(PConstants.MACOSX, opposite)) { // should always be true throw new SketchException( "To use " + library.getName() + ", " + "switch to " + opposite + "-bit mode in Preferences."); // } } else { throw new SketchException( library.getName() + " is only compatible " + "with the " + opposite + "-bit download of Processing."); // throw new SketchException(library.getName() + " does not run in " + bits + "-bit // mode."); // "To use this library, switch to 32-bit mode in Preferences." (OS X) // "To use this library, you must use the 32-bit version of Processing." } } } }
/** * Provide more useful explanations of common error messages, perhaps with a short message in the * status area, and (if necessary) a longer message in the console. * * @param exceptionClass Class name causing the error (with full package name) * @param message The message from the exception * @param listener The Editor or command line interface that's listening for errors * @return true if the error was purtified, false otherwise */ public static boolean handleCommonErrors( final String exceptionClass, final String message, final RunnerListener listener, final PrintStream err) { if (exceptionClass.equals("java.lang.OutOfMemoryError")) { if (message.contains("exceeds VM budget")) { // TODO this is a kludge for Android, since there's no memory preference listener.statusError( "OutOfMemoryError: This code attempts to use more memory than available."); err.println("An OutOfMemoryError means that your code is either using up too much memory"); err.println( "because of a bug (e.g. creating an array that's too large, or unintentionally"); err.println("loading thousands of images), or simply that it's trying to use more memory"); err.println("than what is supported by the current device."); } else { listener.statusError( "OutOfMemoryError: You may need to increase the memory setting in Preferences."); err.println("An OutOfMemoryError means that your code is either using up too much memory"); err.println( "because of a bug (e.g. creating an array that's too large, or unintentionally"); err.println( "loading thousands of images), or that your sketch may need more memory to run."); err.println( "If your sketch uses a lot of memory (for instance if it loads a lot of data files)"); err.println( "you can increase the memory available to your sketch using the Preferences window."); } } else if (exceptionClass.equals("java.lang.UnsatisfiedLinkError")) { listener.statusError("A library used by this sketch is not installed properly."); err.println("A library relies on native code that's not available."); err.println( "Or only works properly when the sketch is run as a " + ((Base.getNativeBits() == 32) ? "64-bit " : "32-bit ") + " application."); } else if (exceptionClass.equals("java.lang.StackOverflowError")) { listener.statusError("StackOverflowError: This sketch is attempting too much recursion."); err.println("A StackOverflowError means that you have a bug that's causing a function"); err.println("to be called recursively (it's calling itself and going in circles),"); err.println("or you're intentionally calling a recursive function too much,"); err.println("and your code should be rewritten in a more efficient manner."); } else if (exceptionClass.equals("java.lang.UnsupportedClassVersionError")) { listener.statusError( "UnsupportedClassVersionError: A library is using code compiled with an unsupported version of Java."); err.println( "This version of Processing only supports libraries and JAR files compiled for Java 1.6 or earlier."); err.println("A library used by this sketch was compiled for Java 1.7 or later, "); err.println("and needs to be recompiled to be compatible with Java 1.6."); } else if (exceptionClass.equals("java.lang.NoSuchMethodError") || exceptionClass.equals("java.lang.NoSuchFieldError")) { listener.statusError( exceptionClass.substring(10) + ": " + "You may be using a library that's incompatible " + "with this version of Processing."); } else { return false; } return true; }