Closed ghost closed 9 years ago
You might try out img.loadPixels()
@ setup() by chance?
http://processingjs.org/reference/PImage_loadPixels_/
you can't access pixels without first calling loadPixels. See the link @GoToLoop mentioned. Although it doesn't need to be called in setup()
, it just needs to be called before you access the .pixels
array
I've advised calling it @ setup() b/c the PImage is static and never changes. :P
/* @pjs preload="tux.png"; */
void setup(){
size(screen.width, screen.height, P3D);
int halfImage = width*height/2;
PImage myImage = loadImage("tux.png");
myImage.loadPixels();
for (int i = 0; i < halfImage; i++) {
myImage.pixels[i+halfImage] = pixels[i];
}
myImage.updatePixels();
image(myImage, 0, 0);
}
Uncaught TypeError: Cannot read property '3' of undefined p.pixels.getPixel setup executeSketch (anonymous function)
Problem still be same.
interesting, that updated code shows there might be a bug in pixels. do you have this running live somewhere so it can be examined by any chance?
https://drive.google.com/file/d/0Bwcv1U0OE_--LWZIUmVWRkh3dzg/view?usp=sharing
Now I can just share with google drive
that just the code though, I meant as running sketch (if it can run: how do I run this? =)
There is a cketch - https://drive.google.com/file/d/0Bwcv1U0OE_--X2YtejAwVUJLT1k/view?usp=sharing
Your loop condition is too big! While loaded image is mere 256x256, your loop expects half of 800x600!
It comes to a point where it gets outta bounds. And after that those indices are all undefined
.
That is @ JS Mode. In Java Mode it raises NullPointerException rather than a somewhat mysterious "TypeError: 'undefined' is not an object".
Since your sketch fails in Java Mode already, you shouldn't have even bothered nor reported a PJS issue! @_@
800x600 is only 480000, that comfortably fits in a desktop browser's running memory. It might cause an error in Java if you're not running with "sensible" min/max heap values, but for Processing.js those values aren't anywhere near problematic (I regularly work on 1200x1200 sketches).
That said, the advice "make sure it works in the PDE, because if that works but Pjs doesn't, it's a bug" is good advice. If the code won't run in the PDE, fix that first, then once that works move to Pjs again.
closing with https://github.com/processing-js/processing-js/issues/142 filed as followup
I also having trouble with the loadPixels()/updatePixles() functions when using processing js. I have a sketch on processing that works fine but when i tried embedding it in a website and using js the loadPixels() fails.
Arseniusz- about the error your get when running the example code it seems that it is because of the line myImage.pixels[i+halfImage] = pixels[i]; which should be myImage.pixels[i+halfImage] = myImage.pixels[i]; but eventhough it gets rid of the "Cannot read property '3' of undefined" error it still not working.
did any of you found a solution??? Thanks
}
When I use 2D mode i get
Uncaught TypeError: Cannot read property 'data' of undefined - processing.js:18301 getPixel - processing.js:18301 draw - VM48:21 Drawing2D.redraw - processing.js:13468 (anonymous function) - processing.js:13550