# Loading images sometimes works and sometimes doesn't

**URL:** <https://discourse.processing.org/t/loading-images-sometimes-works-and-sometimes-doesnt/2562>\
**Category:** Coding Questions\
**Created:** [August 11, 2018, 7:40pm UTC](https://discourse.processing.org/t/loading-images-sometimes-works-and-sometimes-doesnt/2562 "2018-08-11T19:40:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pork](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/pork/32/1034_2.png) [@Pork](https://discourse.processing.org/u/Pork)\
**Post date:** [August 11, 2018, 7:40pm UTC](https://discourse.processing.org/t/loading-images-sometimes-works-and-sometimes-doesnt/2562/1 "2018-08-11T19:40:11Z")

</div>

[Here’s](https://petercpark.github.io/p5.jsParallaxEffect/) what I’m trying to do.

Sometimes when you refresh it works just fine.  
Sometimes I get this error:  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/9/98d2bab631f10b65c6f25473f84e467ceaf53df8.png)  
If you can’t see its says:  
Uncaught TypeError: Cannot read property ‘width’ of undefined  
at e.image (p5.min.js:9)  
at draw (sketch.js:87)  
at e.redraw (p5.min.js:8)  
at e. (p5.min.js:7)

There’s a link to the Github page with all the code in it in the website. All of the code is in the sketch.js file.

Is there something I’m doing wrong? Or is this a p5.js bug? I also wish to know what’s wrong in this situation.

---

<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:** [August 11, 2018, 8:03pm UTC](https://discourse.processing.org/t/loading-images-sometimes-works-and-sometimes-doesnt/2562/2 "2018-08-11T20:03:47Z")

</div>

You’d make things much easier for you if you’d just stick to **preload()** to load ALL of your assets! 🙄

---

<div class="post-metadata">

**Author:** ![Pork](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/pork/32/1034_2.png) [@Pork](https://discourse.processing.org/u/Pork)\
**Post date:** [August 11, 2018, 8:14pm UTC](https://discourse.processing.org/t/loading-images-sometimes-works-and-sometimes-doesnt/2562/3 "2018-08-11T20:14:20Z")

</div>

I want to show the loading icon so that’s why I put them in setup. I put the loading icon in preload.

---

<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:** [August 11, 2018, 8:23pm UTC](https://discourse.processing.org/t/loading-images-sometimes-works-and-sometimes-doesnt/2562/4 "2018-08-11T20:23:25Z")

</div>

> [@Pork](#):
>
> I want to show the loading icon…

- [p5.js overview · processing/p5.js Wiki · GitHub](http://GitHub.com/processing/p5.js/wiki/p5.js-overview#loading-screen)
