PShape and runSketch NullPoinerException issue

I am trying to open a second window using runSketch on processing 3...

it works, until I try to import a PShape obj file.

obj file in this folder:

PShape obj file can be imported, IF, i give up the second window ... :| it is frustrating...

Is there any other way I can build a fullScreen window as a second window without extending PApplet, just using frame or surface?

PShape s;

void setup() {
  size(100, 100,P3D);

  String[] args = {"YourSketchNameHere"};
  SecondApplet sa = new SecondApplet();
  PApplet.runSketch(args, sa);

  s = loadShape("box1.obj"); // in order to open 2 windows, i need to comment this and //shape(s,0,0);
}

void draw() {
  background(0);
  ellipse(50, 50, 10, 10);
  text("MAIN",40,40);
  shape(s, 0, 0); 
}     

//if I remove code below and comment its calling lines at setup() obj file will be imported.
public class SecondApplet extends PApplet {

  public void settings() {
    fullScreen(P3D, 2);
  }
  public void draw() {
    background(255);
    fill(0);
    ellipse(100, 50, 10, 10);
  }
}

this next code is just a variation, but still same problem.

PShape s;

void setup() {
  size(200, 200, P3D);
  s = loadShape("box.obj");
  SecondApplet cp = new SecondApplet("controlWindow");

}

void draw() {
  background(0);
  ellipse(50, 50, 10, 10);
  text("MAIN", 40, 40);
  shape(s, 0, 0);
}     

public class SecondApplet extends PApplet {

  SecondApplet(String _name) {
    super();   
    PApplet.runSketch(new String[]{this.getClass().getName()}, this);
  }
  void settings() {
    fullScreen(P3D, 2);
  }
  void draw() {
    background(255);
    fill(0);
    ellipse(100, 50, 10, 10);
  }
}

Answers

  • edited May 2016 Answer ✓

    Only 1 of the PApplet instances can use some renderer which isn't JAVA2D! [-X
    We can at least have as many PApplet using JAVA2D renderer though. >-)

    // forum.Processing.org/two/discussion/16669/
    // pshape-and-runsketch-nullpoinerexception-issue
    
    // GoToLoop (2016-May-18)
    
    PShape s;
    
    void settings() {
      size(640, 360, P3D);
      smooth(4);
      noLoop();
    
      SecondApplet sa = new SecondApplet();
      PApplet.runSketch(platformNames, sa);
    }
    
    void setup() {
      fill(-1);
      noStroke();
    
      s = loadShape("box.obj");
    }
    
    void draw() {
      background(0);
      ellipse(width>>2, height>>2, width>>2, height>>2);
      text("MAIN", 40, 40);
      shape(s, width>>1, height>>1);
    }     
    
    class SecondApplet extends PApplet {
      void settings() {
        fullScreen(2);
        smooth(4);
        noLoop();
      }
    
      void setup() {
        fill(0);
        noStroke();
      }
    
      void draw() {
        background(-1);
        ellipse(width>>1, height>>1, width>>1, height>>1);
      }
    }
    
  • Thank you very much! I didn't test it yet, but I am afraid It means I can't draw the same 3D object on both windows...if this is the case, I need to think if its possible to have a different approach...

  • Maybe @quark's GWindow class from his GP4 library can pull that out. :-/

  • edited May 2016

    G4P (for Processing 3) supports multiple P2D windows so you should be able to draw the same PShape to more than one window.

  • edited May 2016

    @quark, @bontempos is asking about P3D, not P2D. L-)
    Anyways, I wonder which trick your GWindow class employs in order to get around multiple OpenGL PApplet renderer's limitation. 8-}

  • My mistake, although G4P allows you to open multiple windows they can't be used without generating an error, I just tried. So forget G4P it won't solve your problem. :(

  • edited May 2016

    Oh, that's sad! :( Anywayz, just found out we can have 1 PApplet FX2D renderer + 1 of either P2D or P3D + as many JAVA2D. B-)

  • ow, so, in the end I can only use one P3D, right? opening 2 separated applets and establishing some connection btw them to send information about the object could be an option?

Sign In or Register to comment.