Loading...
Logo
Processing Forum
I am getting this error: 
Copy code
  1. Exception in thread "Animation Thread" java.lang.RuntimeException: PTexture: wrong length of pixels array
  2. at processing.opengl.PTexture.set(PTexture.java:246)
  3. at processing.opengl.PGraphicsOpenGL.updateTexture(PGraphicsOpenGL.java:6972)
  4. at processing.opengl.PGraphicsOpenGL.getTexture(PGraphicsOpenGL.java:6941)
  5. at processing.opengl.PGraphicsOpenGL.renderTriangles(PGraphicsOpenGL.java:2702)
  6. at processing.opengl.PGraphicsOpenGL.endShape(PGraphicsOpenGL.java:1962)
  7. at processing.core.PGraphics.endShape(PGraphics.java:1376)
  8. at processing.core.PGraphics.imageImpl(PGraphics.java:3159)
  9. at processing.core.PGraphics.image(PGraphics.java:3015)
  10. at processing.core.PApplet.image(PApplet.java:10664)
  11. at Atomos_v1_0$Atom.display(Atomos_v1_0.java:70)
  12. at Atomos_v1_0.draw(Atomos_v1_0.java:32)
  13. at processing.core.PApplet.handleDraw(PApplet.java:1891)
  14. at processing.core.PApplet.run(PApplet.java:1788)
  15. at java.lang.Thread.run(Thread.java:680)
however my code is telling me that the w*h of my PGraphics object and the length of the pixels array is the same see the code below:
Copy code
  1. Atom atom;

  2. public void setup(){
  3.   size(960, 600, P3D);
  4.   color c = color(14, 147, 193);
  5.   atom = new Atom(new PVector(width/2, height/2), new PVector(0, 0), 150, c);
  6.   
  7. }

  8. public void draw(){
  9.   background(100);
  10.   atom.display();
  11. }

  12. public class Atom{
  13.   
  14.   PVector loc, vel;
  15.   int size;
  16.   color atomColor;
  17.   PGraphics pg;
  18.   
  19.   Atom(PVector _loc, PVector _vel, int _size, color _atomColor){
  20.     this.loc = _loc;
  21.     this.vel = _vel;
  22.     this.size = _size;
  23.     this.atomColor = _atomColor;
  24.     this.pg = new PGraphics();
  25.     this.pg = createGraphics(this.size, this.size, P2D);
  26.     this.pg.beginDraw();
  27.     PVector center = new PVector(this.size/2, this.size/2);
  28.     
  29.     for(int x = 0; x <= this.size; x++){
  30.       for(int y = 0; y <= this.size; y++){
  31.         PVector point = new PVector(x, y);
  32.         float distance = PVector.dist(center, point);
  33.         float maxDist = this.pg.width/2;
  34.         float distCoeff = map(distance, 0, maxDist, 255, 0);
  35.         int thisColor = color(this.atomColor, distCoeff);
  36.         this.pg.set(x, y, thisColor);
  37.         println("("+x+", "+y+") = "+"("+red(thisColor)+", "+green(thisColor)+", "+blue(thisColor)+")");
  38.       }
  39.     }
  40.     this.pg.loadPixels();
  41.     println(this.size*this.size);
  42.     println(this.pg.pixels.length);
  43.     pg.endDraw();
  44.   }
  45.   
  46.   public void display(){
  47.     imageMode(CENTER);
  48.     image(this.pg, this.loc.x, this.loc.y);
  49.   }
  50. }
and i get this output: 
Copy code
  1. ...
  2. (149, 147) = (0.0, 0.0, 0.0)
  3. (149, 148) = (0.0, 0.0, 0.0)
  4. (149, 149) = (0.0, 0.0, 0.0)
  5. 22500
  6. 22500
i read about an issue with the PTexture error on the processing googlecode site here:  http://code.google.com/p/processing/issues/detail?id=829. It says that it has been resolved however i'm getting the error on 2.0a1. anyone know how i can use 2d graphics on a 3d view...if that makes any sense

Replies(1)

" i'm getting the error on 2.0a1"
That's the version on which the error has been reported. The fix is recent, wait for a new release.