The pixels array is null using setTexture()

Running the simple sketch below on Android I keep getting “The pixels array is null.” error. The error does not happen when I use Java mode on my computer. From what I’ve read this error is usually caused by a missing loadPixels() but I understand I should only be using that when I’m actually working on the pixels array and this isn’t. Adding loadPixels() does not fix the issue in any case. setTexture() seems to be the issue but the texture loads and displays just fine. Is there something I’m missing here - a Android permission, a library I should be loading?

//radius of sphere
float sphereradius = 100;

//the sphere shape
PImage thetexture;
PShape thesphere;

//when the app first runs
void setup()
  //set fullscreen, 3D mode and portrait

  //load an image
  thetexture = loadImage("red-chevron.jpg");

  //disable stroke

  //create a sphere shape and set the image as its texture
  thesphere = createShape(SPHERE, sphereradius);
  thesphere.setTexture(thetexture); //<-- the setTexture() causes the error

//the looping function of the app
void draw()
  //set the background colour as green/blue (refresh the screen)
  background(0, 200, 200);

  //activate lights (shadow on sphere)
  //translate to screen centre - this is used as the sphere's starting point (0, 0)
  translate(width / 2, height / 2, 0);

  //show sphere shape

Could you post the picture?


Nothing wrong with it, it was a downloaded image but pushed it through Gimp just in case.

I’ve just tested it on APDE. Running perfectly!

It’s loading and displaying fine here too but as I said the console shows the error “The pixels array is null.”. I can ignore it but it shouldn’t do this.

I don’t get any error or warning.

I have the same issue. I am not using APDE, which is why noel doesn’t see the issue. But on a PC the issue exists on multiple Android mode sketches that I’ve written. And as garrettlynch mentioned not in Java Mode. I’ve been ignoring it. The issue wasn’t there a couple of years ago. I’ve been hoping someone from the Processing Foundation would address this seemingly harmless glitch. All I’m doing in any of my sketches is loading and resizing an image; nothing more.

1 Like

The error message only pops up when I create an image object. It does not affect the running sketch

Ok, I have found that if I use img.loadPixels() after I us img = loadImage(“filename”), the error message does not pop up. And the error message only pops up when I display the img, in draw()

1 Like