Exemplo n.º 1
0
  // made synchronized for 0087
  // attempted to remove synchronized for 0136 to fix bug #775 (no luck tho)
  // http://dev.processing.org/bugs/show_bug.cgi?id=775
  public synchronized void message(String s) {
    //    System.out.println("M" + s.length() + ":" + s.trim()); // + "MMM" + s.length());

    // this eats the CRLFs on the lines.. oops.. do it later
    // if (s.trim().length() == 0) return;

    // this is PApplet sending a message (via System.out.println)
    // that signals that the applet has been quit.
    if (s.indexOf(PApplet.EXTERNAL_STOP) == 0) {
      // System.out.println("external: quit");
      if (editor != null) {
        //        editor.internalCloseRunner();  // [091124]
        //        editor.handleStop();  // prior to 0192
        editor.internalCloseRunner(); // 0192
      }
      return;
    }

    // this is the PApplet sending us a message that the applet
    // is being moved to a new window location
    if (s.indexOf(PApplet.EXTERNAL_MOVE) == 0) {
      String nums = s.substring(s.indexOf(' ') + 1).trim();
      int space = nums.indexOf(' ');
      int left = Integer.parseInt(nums.substring(0, space));
      int top = Integer.parseInt(nums.substring(space + 1));
      // this is only fired when connected to an editor
      editor.setSketchLocation(new Point(left, top));
      // System.out.println("external: move to " + left + " " + top);
      return;
    }

    // these are used for debugging, in case there are concerns
    // that some errors aren't coming through properly
    //    if (s.length() > 2) {
    //      System.err.println(newMessage);
    //      System.err.println("message " + s.length() + ":" + s);
    //    }

    // always shove out the message, since it might not fall under
    // the same setup as we're expecting
    sketchErr.print(s);
    // System.err.println("[" + s.length() + "] " + s);
    sketchErr.flush();
  }
Exemplo n.º 2
0
  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."
        }
      }
    }
  }
Exemplo n.º 3
0
  /**
   * 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;
  }