# Sketch crashing as soon as it starts playing

**URL:** <https://discourse.processing.org/t/sketch-crashing-as-soon-as-it-starts-playing/40955>\
**Category:** Beginners\
**Created:** [February 17, 2023, 2:47pm UTC](https://discourse.processing.org/t/sketch-crashing-as-soon-as-it-starts-playing/40955 "2023-02-17T14:47:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bdooley](https://avatars.discourse-cdn.com/v4/letter/b/7cd45c/32.png) [@bdooley](https://discourse.processing.org/u/bdooley)\
**Post date:** [February 17, 2023, 2:47pm UTC](https://discourse.processing.org/t/sketch-crashing-as-soon-as-it-starts-playing/40955/1 "2023-02-17T14:47:59Z")

</div>

Hi,

I am trying to make a sketch with falling squares and circles that collide with each other as well as the right and left wall and ground, but am having trouble with the sketch crashing as soon as pressing play, without even the background being drawn or giving any error messages.

[https://editor.p5js.org/bdooley7/sketches/vKKaXEzy5](https://editor.p5js.org/bdooley7/sketches/vKKaXEzy5)

I would appreciate any help as to why this may be happening.

Thank you so much in advance!

---

<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:** [February 17, 2023, 2:51pm UTC](https://discourse.processing.org/t/sketch-crashing-as-soon-as-it-starts-playing/40955/2 "2023-02-17T14:51:11Z")

</div>

> [@bdooley](#):
>
> , but am having trouble with the sketch crashing as soon as pressing play,

Maybe you shouldn’t declare anything named Object:

> **[Object - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
>
> The Object type represents one of JavaScript's data types. It is used to store various keyed collections and more complex entities. Objects can be created using the Object() constructor or the object initializer / literal syntax.

---

<div class="post-metadata">

**Author:** ![bdooley](https://avatars.discourse-cdn.com/v4/letter/b/7cd45c/32.png) [@bdooley](https://discourse.processing.org/u/bdooley)\
**Post date:** [February 17, 2023, 4:01pm UTC](https://discourse.processing.org/t/sketch-crashing-as-soon-as-it-starts-playing/40955/3 "2023-02-17T16:01:21Z")

</div>

Thank you so much ! This got the background to draw and error messages to show up!

Now I receive a “TypeError: object1.collideWithBoundaries is not a function at /sketch.js:51:13”, and if I comment out this line, there are a bunch of other errors. Is there something fundamentally wrong with the code?

Thanks again!

---

<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:** [February 17, 2023, 4:09pm UTC](https://discourse.processing.org/t/sketch-crashing-as-soon-as-it-starts-playing/40955/4 "2023-02-17T16:09:48Z")

</div>

> [@bdooley](#):
>
> “TypeError: object1.collideWithBoundaries is not a function at /sketch.js:51:13”

All your subclasses define a method named **collideWith()**, but none **collideWithBoundaries()**.

---

<div class="post-metadata">

**Author:** ![bdooley](https://avatars.discourse-cdn.com/v4/letter/b/7cd45c/32.png) [@bdooley](https://discourse.processing.org/u/bdooley)\
**Post date:** [February 17, 2023, 8:50pm UTC](https://discourse.processing.org/t/sketch-crashing-as-soon-as-it-starts-playing/40955/5 "2023-02-17T20:50:36Z")

</div>

Hi, thank you! I have one last question : now I receive the error “TypeError: v.copy is not a function”.

I’m using the variable v in the “applyImpulse”, however when I comment these out, the same error “v.copy is not a function” is given. Does this have to do with how I’m using p5.Vector.div and object1.applyForce(GRAVITY); ?

---

<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:** [February 17, 2023, 9:39pm UTC](https://discourse.processing.org/t/sketch-crashing-as-soon-as-it-starts-playing/40955/6 "2023-02-17T21:39:25Z")

</div>

> [@bdooley](#):
>
> Does this have to do with how I’m using p5.Vector.**div()** and `object1.applyForce(GRAVITY)`?

This is how your Shape::**applyForce(_force_)** method is implemented:

```auto
applyForce(force) {
  let f = p5.Vector.div(force, this.mass);
  this.acc.add(f);
}

```

Static method p5.Vector.**div()** requires its 1st parameter to be of type p5.Vector.

But the argument _GRAVITY_ passed to parameter _force_ is a number: `const GRAVITY = 0.5;`
