wrong length of pixels array error but the lengths are the same
in
Core Library Questions
•
1 years ago
I am getting this error:
- Exception in thread "Animation Thread" java.lang.RuntimeException: PTexture: wrong length of pixels array
- at processing.opengl.PTexture.set(PTexture.java:246)
- at processing.opengl.PGraphicsOpenGL.updateTexture(PGraphicsOpenGL.java:6972)
- at processing.opengl.PGraphicsOpenGL.getTexture(PGraphicsOpenGL.java:6941)
- at processing.opengl.PGraphicsOpenGL.renderTriangles(PGraphicsOpenGL.java:2702)
- at processing.opengl.PGraphicsOpenGL.endShape(PGraphicsOpenGL.java:1962)
- at processing.core.PGraphics.endShape(PGraphics.java:1376)
- at processing.core.PGraphics.imageImpl(PGraphics.java:3159)
- at processing.core.PGraphics.image(PGraphics.java:3015)
- at processing.core.PApplet.image(PApplet.java:10664)
- at Atomos_v1_0$Atom.display(Atomos_v1_0.java:70)
- at Atomos_v1_0.draw(Atomos_v1_0.java:32)
- at processing.core.PApplet.handleDraw(PApplet.java:1891)
- at processing.core.PApplet.run(PApplet.java:1788)
- 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:
- Atom atom;
- public void setup(){
- size(960, 600, P3D);
- color c = color(14, 147, 193);
- atom = new Atom(new PVector(width/2, height/2), new PVector(0, 0), 150, c);
- }
- public void draw(){
- background(100);
- atom.display();
- }
- public class Atom{
- PVector loc, vel;
- int size;
- color atomColor;
- PGraphics pg;
- Atom(PVector _loc, PVector _vel, int _size, color _atomColor){
- this.loc = _loc;
- this.vel = _vel;
- this.size = _size;
- this.atomColor = _atomColor;
- this.pg = new PGraphics();
- this.pg = createGraphics(this.size, this.size, P2D);
- this.pg.beginDraw();
- PVector center = new PVector(this.size/2, this.size/2);
- for(int x = 0; x <= this.size; x++){
- for(int y = 0; y <= this.size; y++){
- PVector point = new PVector(x, y);
- float distance = PVector.dist(center, point);
- float maxDist = this.pg.width/2;
- float distCoeff = map(distance, 0, maxDist, 255, 0);
- int thisColor = color(this.atomColor, distCoeff);
- this.pg.set(x, y, thisColor);
- println("("+x+", "+y+") = "+"("+red(thisColor)+", "+green(thisColor)+", "+blue(thisColor)+")");
- }
- }
- this.pg.loadPixels();
- println(this.size*this.size);
- println(this.pg.pixels.length);
- pg.endDraw();
- }
- public void display(){
- imageMode(CENTER);
- image(this.pg, this.loc.x, this.loc.y);
- }
- }
and i get this output:
- ...
- (149, 147) = (0.0, 0.0, 0.0)
- (149, 148) = (0.0, 0.0, 0.0)
- (149, 149) = (0.0, 0.0, 0.0)
- 22500
- 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
1