# My code is "crashing" the editor. What is wrong?

**URL:** https://discourse.processing.org/t/my-code-is-crashing-the-editor-what-is-wrong/8939
**Category:** Coding Questions
**Created:** [March 4, 2019, 6:41pm UTC](https://discourse.processing.org/t/my-code-is-crashing-the-editor-what-is-wrong/8939 "2019-03-04T18:41:02Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Lillbre](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lillbre/32/18325_2.png) [@Lillbre](https://discourse.processing.org/u/Lillbre)
#### Post date: [March 4, 2019, 6:41pm UTC](https://discourse.processing.org/t/my-code-is-crashing-the-editor-what-is-wrong/8939/1 "2019-03-04T18:41:02Z")

</div>

I made a code for a magnifier glass in p5.js. It works but the editor shuts down after a short time. Can someone please look at it and see what is wrong? [The code in p5.js editor](https://editor.p5js.org/Lillbre/sketches/4qHM4igSf)

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [March 4, 2019, 6:48pm UTC](https://discourse.processing.org/t/my-code-is-crashing-the-editor-what-is-wrong/8939/2 "2019-03-04T18:48:50Z")

</div>

- [Forum.Processing.org/two/discussion/22039/using-creategraphics-get-in-the-draw-loop-causing-memory-usage#Item\_4](http://Forum.Processing.org/two/discussion/22039/using-creategraphics-get-in-the-draw-loop-causing-memory-usage#Item_4)

---

<div class="post-metadata">

### Author: ![Lillbre](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lillbre/32/18325_2.png) [@Lillbre](https://discourse.processing.org/u/Lillbre)
#### Post date: [March 4, 2019, 7:01pm UTC](https://discourse.processing.org/t/my-code-is-crashing-the-editor-what-is-wrong/8939/3 "2019-03-04T19:01:37Z")

</div>

Thank you! Do you have an example how I could rewrite my code? I am not so good at this yet 😱

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [March 5, 2019, 1:27am UTC](https://discourse.processing.org/t/my-code-is-crashing-the-editor-what-is-wrong/8939/4 "2019-03-05T01:27:12Z")

</div>

> [@Lillbre](#):
>
> rewrite my code?

following @GoToLoop 's tip:  
just move the line

```auto
	magni = createGraphics(400, 400);

```

up to setup and it works

---

<div class="post-metadata">

### Author: ![Lillbre](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lillbre/32/18325_2.png) [@Lillbre](https://discourse.processing.org/u/Lillbre)
#### Post date: [March 5, 2019, 4:55am UTC](https://discourse.processing.org/t/my-code-is-crashing-the-editor-what-is-wrong/8939/5 "2019-03-05T04:55:59Z")

</div>

If I move magni = createGraphics(400, 400); to setup the magnifier circle draws a trail to the canvas when I move it.

---

<div class="post-metadata">

### Author: ![hotfooted](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hotfooted/32/3670_2.png) [@hotfooted](https://discourse.processing.org/u/hotfooted)
#### Post date: [March 5, 2019, 5:03am UTC](https://discourse.processing.org/t/my-code-is-crashing-the-editor-what-is-wrong/8939/6 "2019-03-05T05:03:46Z")

</div>

do as kll said but add magni.clear() to the draw

---

<div class="post-metadata">

### Author: ![Lillbre](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lillbre/32/18325_2.png) [@Lillbre](https://discourse.processing.org/u/Lillbre)
#### Post date: [March 5, 2019, 5:39am UTC](https://discourse.processing.org/t/my-code-is-crashing-the-editor-what-is-wrong/8939/7 "2019-03-05T05:39:23Z")

</div>

Thank you so much!! Now it is working!!🥰
