# What causes a graphical sketch to start glitching out?

**URL:** <https://discourse.processing.org/t/what-causes-a-graphical-sketch-to-start-glitching-out/21458>\
**Category:** Coding Questions\
**Created:** [May 31, 2020, 1:45pm UTC](https://discourse.processing.org/t/what-causes-a-graphical-sketch-to-start-glitching-out/21458 "2020-05-31T13:45:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BennyHacker](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bennyhacker/32/2969_2.png) [@BennyHacker](https://discourse.processing.org/u/BennyHacker)\
**Post date:** [May 31, 2020, 1:45pm UTC](https://discourse.processing.org/t/what-causes-a-graphical-sketch-to-start-glitching-out/21458/1 "2020-05-31T13:45:18Z")

</div>

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…

> **[bennyHacker/Weird-glitch](https://github.com/bennyHacker/Weird-glitch)**
>
> Processing, why are you so broken? Contribute to bennyHacker/Weird-glitch development by creating an account on GitHub.

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?

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [May 31, 2020, 2:59pm UTC](https://discourse.processing.org/t/what-causes-a-graphical-sketch-to-start-glitching-out/21458/2 "2020-05-31T14:59:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![BennyHacker](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bennyhacker/32/2969_2.png) [@BennyHacker](https://discourse.processing.org/u/BennyHacker)\
**Post date:** [May 31, 2020, 3:44pm UTC](https://discourse.processing.org/t/what-causes-a-graphical-sketch-to-start-glitching-out/21458/3 "2020-05-31T15:44:54Z")

</div>

You guys wanna know what the “bug” was?

```auto
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.

---

<div class="post-metadata">

**Author:** ![noahbuddy](https://avatars.discourse-cdn.com/v4/letter/n/73ab20/32.png) [@noahbuddy](https://discourse.processing.org/u/noahbuddy)\
**Post date:** [May 31, 2020, 7:20pm UTC](https://discourse.processing.org/t/what-causes-a-graphical-sketch-to-start-glitching-out/21458/4 "2020-05-31T19:20:39Z")

</div>

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:

```auto
  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.
