Loading...
Logo
Processing Forum

Hello All,

I am using NApplet library in my processing sketch.But when I copied my another application into a NApplet following exception occured:

java.lang.RuntimeException: Too many calls to pushMatrix().
at processing.core.PGraphics2D.pushMatrix(Unknown Source)
at processing.core.PApplet.pushMatrix(Unknown Source)
at napplet.NAppletManager.draw(Unknown Source)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at processing.core.PApplet$RegisteredMethods.handle(Unknown Source)
at processing.core.PApplet$RegisteredMethods.handle(Unknown Source)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:619)

Now to adjust the depth of pushmatrix I copied folllowing code from http://wiki.processing.org/w/Matrix_stack site :

// adjust this value to whatever depth is actually necessary
public final int STACK_DEPTH 10000;
public 
float[][] matrixStack = new float[STACK_DEPTH][6];

 
// this version will override the built-in version pushMatrix function
public void pushMatrix() {
  println
("hello");
  if (
matrixStackDepth == 10000{
      println
("exception");
    throw new 
RuntimeException("too many calls to pushMatrix()");
  
}
  this
.g.getMatrix().get(matrixStack[matrixStackDepth]);
  
matrixStackDepth++;
}
 
// this version will override the built-in version popMatrix function
public void popMatrix() {
  
if (matrixStackDepth == 0{
    
throw new RuntimeException("too many calls to popMatrix()" +
                               
"(or too few to pushMatrix)");
  
}
  matrixStackDepth
--;
  
PMatrix2D m = new PMatrix2D();
  
m.set(matrixStack[matrixStackDepth]);
  
this.g.setMatrix(m);
}

again following exception is thrown :

java.lang.NullPointerException
at sketch_may28a.pushMatrix(sketch_may28a.java:275)
at napplet.NAppletManager.draw(Unknown Source)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at processing.core.PApplet$RegisteredMethods.handle(Unknown Source)
at processing.core.PApplet$RegisteredMethods.handle(Unknown Source)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:619)

Can anyone there please help solve this issue??

Thanks in advance

Replies(1)

My code is as follows :

Copy code
  1. import napplet.*;
     
    import TUIO.*;
    import fullscreen.*;
    NAppletManager nappletManager 

    void setup()
    {
       size
    (screen.width,screen.height,P2D);
       
    nappletManager = new NAppletManager(this);
       
    nappletManager.createNApplet("inbox"100,100);   
    }

    public class inbox extends NApplet
    {
     
          TuioProcessing tuioClient
    ;
          
    float X,Y,oldX,oldY;

          
    int particleCount 20000;
          
    float halfWidth
          
    float halfHeight;
          
    float angle 0// The perspective the canvas is being viewed at
          
    Particle [] dust = new Particle[particleCount+1]// Our array of particles
         
    PImage bg;
    /* Setup */
    void setup () 
    {
      size
    (510,500);
      
    //fs  = new FullScreen(this);
      //fs.enter();
      
    bg loadImage("p6.jpg");
      
    background(bg);
      
    halfWidth width/2;
      
    halfHeight height/2;
      
      
    colorMode(HSB,100); // Color will be set by hue, saturation, and brightness, and it will be set by 0-100.
      
    initTUIO();
     
    for (int i particleCount>= 0i--)
      

         float tempAngle 
    random(PI);
  2.   float tempDist random(130);   dust[i] = new Particle
         
    (
             new 
    PVector(
                 
    tempDist cos(tempAngle), // position on x axis
                 
    -150// on y axis (how high)
                 
    tempDist sin(tempAngle// position on z axis
                 
    )
         );
      
      
    }
      resize
    (510,500);
      
    }

    void draw () 
    {
      translate
    (halfWidthhalfHeight);
      
    background(bg);
      
    angle 0.005;
        
    stroke(100); 
        for (
    int j particleCount>= 0j--) 
            
    {
                    
    // Loop through each particle and update it.
                   
    dust[j].update(X,Y);        
            
    }
    }
     
    /* Particle Class */
    class Particle
    {
      PVector position = new PVector(); // 3D coordinate of the particle's position.
      
    PVector velocity = new PVector(0,0,0); // Not the coordinate, but the speed and direction the particle is traveling along each axis.
      
    PVector last = new PVector(); // The paritcle's last position, used for drawing the other end of the line.
       
      /* Particle Constructor */
      
    Particle (PVector positionP)
      
    {
        position
    .set(positionP);
        
    last.set(position);
      
    }
  3.   void update (float X,float Y
      
    {
        
        PVector reversed 
    = new PVector((halfWidth)/2Y-30-halfHeight
                                           
    0,
                                          (
    halfWidth X)/+Y-30-halfHeight); 
          
          
    reversed rotateVector(reversed, -angle); // Rotate the reversed cursor coordinate to match our perspective.
          
    float distance dist(reversed.xreversed.y-70reversed.zposition.xposition.yposition.z); // The distance between the cursor and the particle.
          
    if (distance 65
          
    {
  4. float angleXZ atan2(reversed.z-position.zreversed.x-position.x);
               
    velocity.add(0.014 * (65 distance 25 noise(angleXZ 3distance 0.1)) * cos(angleXZ + (0.7 0.0005 * (65 distance))),
                         
    0.03 * (65 distance 25 noise(angleXZ 3distance 0.1)),     
                         
    0.014 * (65 distance 25 noise(angleXZ 3distance 0.1)) * sin(angleXZ + (0.7 0.0005 * (65 distance)))); 
            
    }
        
        velocity
    .-= 0.3// Gravity
         
       
    if (velocity.< -0.1 && velocity.> -&& position.< -68velocity.0;
        if (
    position.< -80
        
    {
          position
    .= -80;
          
    velocity.*= -0.7;
        
    }
        
    if (position.100
        
    {
          velocity
    .*= -1;
          
    position.99;
        
    }
        
    if (position.< -100
        
    {
          velocity
    .*= -1;
          
    position.= -99;
        
    }
        
    if (position.100
        
    {
          velocity
    .*= -1;
          
    position.99;
        
    }
        
    if (position.< -100
        
    {
          velocity
    .*= -1;
          
    position.= -99;
        
    }
        position
    .add(velocity); // Add the velocity to the particle's position.
        
    velocity.mult(0.97); // Simulate friction by multiplying velocity by 0.97.
      
       
    PVector rendered render(position); 
        
      
            float pDist dist(100 cos(2*PI -angle),-70,100 sin(2*PI angle), position.xposition.yposition.z);
        
    stroke(60 + (velocity.x+velocity.y+velocity.z)*6,
               
    40 pDist 0.7,
               
    130 pDist 0.5); // The color of the particle. Determined by it's velocity and your perspective (angle)
        
    last.set(render(last)); // Render the last coordinate for the tail.
        
    line(int(rendered.x),int(rendered.y),int(last.x),int(last.y)); // Use integers, because Processing can't draw a pixel accurately at (0.7,0.3)
        
    last.set(position); // Reset last to the current position, for the next frame.
    }
    }
    PVector render (PVector initial
    {
      PVector rotated 
    rotateVector(initialangle); // Rotate the coordinate so it fits our perspective.
      
    PVector finalPoint = new PVector(rotated.rotated.z,
                                      (
    rotated.rotated.z)/rotated.y); // A watered down version of an isometric tile coordinate formula.
        
      
    return finalPoint;
    }
     
    // For rotating things to the correct position
    PVector rotateVector(PVector coordfloat xzAngle
    {       
      float c cos(xzAngle); // use temporary variables for calculating cosine and sine, since these are used more than once and it's a good idea to save resources
      
    float s sin(xzAngle);
      
    PVector tempCoord = new PVector(coord.coord.zcoord.ycoord.coord.z); // Rotate the coordinate
      
    return tempCoord;
  5. }

    void initTUIO
    () 
    {
        tuioClient  
    = new TuioProcessing(this);
    }

    void updateTUIO
    () 
    {      
        
        Vector tuioCursorList 
    tuioClient.getTuioCursors();
        for (
    int i=0;i<tuioCursorList.size();i++) 
        
    {
            TuioCursor tcur 
    = (TuioCursor)tuioCursorList.elementAt(i);
            
    tcur.getScreenX(width);
            
    tcur.getScreenY(height);
            
        
    }
    }


    void addTuioObject
    (TuioObject tobj){
    }

    void updateTuioObject
    (TuioObject tobj) {
    }

    void removeTuioObject
    (TuioObject tobj){
    }
    void addTuioCursor
    (TuioCursor tcur
    {
         X 
    tcur.getScreenX(width);
         
    tcur.getScreenY(height);
    }

    void updateTuioCursor
    (TuioCursor tcur
    {
           X 
    tcur.getScreenX(width);
          
    tcur.getScreenY(height);
    }

    void removeTuioCursor
    (TuioCursor tcur
    {
    }

    void refresh
    (TuioTime bundleTime
    {
      redraw
    ();
    }
     
     }