Why does writing pixels pixels values larger than half an PImage crashes a 3D sketch ?
in
Core Library Questions
•
1 years ago
I don't know if this is a known issue or if I should be attempting to draw a 2D Image on top of a 3D scene.
Here's a basic setup to replicate my problem:
- PImage canvas;
- void setup(){
- size(400,400,P2D);
- // size(400,400,P3D);//this breaks it
- canvas = createImage(200,200,RGB);
- canvas.loadPixels();
- for(int i = 0 ; i < canvas.pixels.length; i++) canvas.pixels[i] = 0x000000;
- canvas.updatePixels();
- }
- void draw(){
- background(255);
- image(canvas,0,0);
- if(mousePressed){
- if(mouseX < 200 && mouseY < 200) {
- canvas.set(mouseX,mouseY,color(0,192,0));
- canvas.updatePixels();
- }
- }
- }
Simply change the renderer to P3D and draw into the canvas. If mouseX or mouseY reach half the canvas size, the program crashes. Why is that and how can I get around the issue ?
1