NullPointerException on GIF animation

edited December 2014 in Questions about Code

I have a "room" with a mask and I am altering the HSB of only the non-masked part of the room. See here for files, explanation, etc..

and I am getting a NullPointerException for my animated GIF. I'm using the gifAnimation Library.

Capture

I get that the null pointer exception is showing that the myAnimation function has failed... but I don't understand why.

Here is my code:

PImage photo, mask, image;
int md = 150;
int md2 = md * 2;
import gifAnimation.*;  // import the gifAnimamtion library

Gif myAnimation;        //creates Gif object called myAnimation

void setup() {
  size(781, 742);
  frameRate(30);
  photo = loadImage("test_cave2.jpg");
  mask = loadImage("test_cave2_mask.jpg");
  colorMode(HSB, 1);
  myAnimation = new Gif(this, "totally_transparent_fire_clipped.gif");  //  load animated GIF file from the data folder
  myAnimation.play();  //play the animated GIF at the above frame rate.
}

void draw() {
  noStroke();
  fill(0);
  rect(0, 0, photo.width, photo.height);
  loadPixels();
  int minX = max(mouseX - md2, 0);
  int maxX = min(mouseX + md2, photo.width);
  int minY = max(mouseY - md2, 0);
  int maxY = min(mouseY + md2, photo.height);
  for (int x=minX; x<maxX; x++) {
    for (int y=minY; y<maxY; y++ ) {
      int loc = x + y * photo.width;
      float mb = brightness(mask.pixels[loc]);
      if (mb > 0.1) {
        float d = dist(x, y, mouseX, mouseY);
        float adjustBrightness = (md - d) / md;
        color c = photo.pixels[loc];
        float b = brightness(c) + adjustBrightness;
        pixels[x + y * width] = color(hue(c), saturation(c), b);
      }
    }
  }
  updatePixels();
  ellipse(mouseX, mouseY, 20, 20);
  image(myAnimation, mouseX-62, mouseY-93); //display the amiate GIF at desired location.
}

Can anyone explain why it is breaking?

Lastly, when I run the gifAnimation code by itself... it works just fine. Here is that code:

// Little program for displaying one animated GIF
// based on the gifAnimation library by Extrapixel 
// http://extrapixel.github.io/gif-animation/ 


import gifAnimation.*;    // import the gifAnimation library

Gif myAnimation;          // create Gif object called myAnimation

void setup() {

  size(800, 800);
  frameRate(30);
  // window size (pixels), use(displayWidth, 
  // displayHeight)for fullscreen size

  myAnimation = new Gif(this, "totally_transparent_fire_clipped.gif"); // load animated GIF file from 
  // the data folder, replace 
  // "img01.gif" with the name of 
  // your GIF file

  myAnimation.play();                       // play the animated GIF
}


void draw() {

  background(0);             // window background color, 255 = white, 0 = 
  // black, RGB values e.g. (43,170,224)

  image(myAnimation, mouseX-62, mouseY-93);  // display the animated GIF, define top left 
  //print(mouseX, mouseY);
  // corner x and y coordinates for the animation
}

Answers

  • Answer ✓

    Works for me. I downloaded a Gif and typed in the Gif's name to line 14. Had the other jpgs from the masking post. Check your Gif name and its location in the data folder.

  • Ooph, egg on my face. I am embarrassed. X_X

    ...but thank you!

    I must have forgot to move everything over.

    I wish there was a better IDE for processing. That could have saved me a few hours! ha ha ha.

Sign In or Register to comment.