What causes a graphical sketch to start glitching out?

Hey forum, sometimes when I’m working on a particularly graphics oriented sketch it will all of a sudden start to behave very strange with no apparent cause.

Has this ever happened to anyone else? I have a sketch that’s doing it right now. I can link a github to it if anyone wants to try to see what’s wrong. I haven’t been able to figure it out myself, but it seems to be related to using different rendering methods…

The bug appears to be happening in the display() method, particularly the raytrace() method.

What should happen: by pressing the arrow keys, the player moves around and the screen updates. Do not click the mouse as it may result in out of bounds exception.

What happens instead: screen updates, but then doesn’t?

I do not have time to look into this now, but it is giving the error “ArrayIndexOutOfBoundsException: -3” in mousePressed() tiles[] all the time.

1 Like

You guys wanna know what the “bug” was?

size(928, 864, P3D);
noSmooth(); //THIS!!!!!!!
screen = createGraphics(320, 194, P3D);

For some reason, calling noSmooth caused the whole program to not function. I guess I should report this as a bug.

1 Like

I have not received an index out of bounds error yet but I think I found the trouble with no display.

At the end of draw(), change the last bit to:

  if (mousePressed) {
    int X = mouseX/32-10+x;
    int Y = mouseY/32-9+y;
    if (mouseButton==LEFT) {   
      tiles[X][Y][z]=(byte)selector;
    } else {
      tiles[X][Y][z]=1;
    }
    //onWorldUpdate();
    handleMove();
  }
  display();

Also add handleMove(); at the end of setup() to initialize.

Indeed, the noSmooth() call appears to affect how the frame is initialized with each call of draw().
If we force the render by calling display(), it seems okay.

2 Likes