# Getting a strange error while using shader

**URL:** <https://discourse.processing.org/t/getting-a-strange-error-while-using-shader/12522>\
**Category:** Coding Questions\
**Created:** [July 5, 2019, 10:35am UTC](https://discourse.processing.org/t/getting-a-strange-error-while-using-shader/12522 "2019-07-05T10:35:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sudev](https://avatars.discourse-cdn.com/v4/letter/s/9de053/32.png) [@Sudev](https://discourse.processing.org/u/Sudev)\
**Post date:** [July 5, 2019, 10:35am UTC](https://discourse.processing.org/t/getting-a-strange-error-while-using-shader/12522/1 "2019-07-05T10:35:22Z")

</div>

Am getting a very strange error when I use shader in my sketch.

```auto
Uncaught TypeError: Cannot read property 'isP3D' of undefined (sketch: line 5)

```

and this is the code

```auto
let img;

function preload(){
   img = loadImage('https://source.unsplash.com/random/1920x1080');
  magnify = createShader('shader/MagnifyingShaderVert.vert', 'shader/MagnifyingShaderVert.frag');  
  antialias = createShader('shader/FXAAShaderVert.vert', 'shader/FXAAShaderVert.frag');
}

function setup() {
  createCanvas(innerWidth, innerHeight, WEBGL);
  
  imageMode(CENTER);
}

function draw() {
  image(img, 0, 0);
  
  noLoop();
}

```

Any help appreciated.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [July 6, 2019, 12:21pm UTC](https://discourse.processing.org/t/getting-a-strange-error-while-using-shader/12522/2 "2019-07-06T12:21:55Z")

</div>

More on the JavaScript error:

> **[Uncaught TypeError: Cannot read property of undefined In JavaScript](https://codeburst.io/uncaught-typeerror-cannot-read-property-of-undefined-in-javascript-c81e00f4a5e3)**
>
> Out of the six primitive types defined in JavaScript, namely boolean, string, symbol, number, Null, and undefined, no other type throws as…

---

<div class="post-metadata">

**Author:** ![figraham](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/figraham/32/4161_2.png) [@figraham](https://discourse.processing.org/u/figraham)\
**Post date:** [July 7, 2019, 12:42am UTC](https://discourse.processing.org/t/getting-a-strange-error-while-using-shader/12522/3 "2019-07-07T00:42:35Z")

</div>

Looks like it could be a problem with loading the shader but it’s hard to tell just from the error. This is kind of a guess but you might need to use `loadShader()` instead of `createShader()` if the shader is in another file. I would recommend trying to get an [example from this book](https://itp-xstory.github.io/p5js-shaders/#/./docs/examples/basic_gradient) working in p5js and then add your own shader.

---

<div class="post-metadata">

**Author:** ![Sudev](https://avatars.discourse-cdn.com/v4/letter/s/9de053/32.png) [@Sudev](https://discourse.processing.org/u/Sudev)\
**Post date:** [July 11, 2019, 12:26pm UTC](https://discourse.processing.org/t/getting-a-strange-error-while-using-shader/12522/4 "2019-07-11T12:26:11Z")

</div>

Thanks for the info mate !

---

<div class="post-metadata">

**Author:** ![Sudev](https://avatars.discourse-cdn.com/v4/letter/s/9de053/32.png) [@Sudev](https://discourse.processing.org/u/Sudev)\
**Post date:** [July 11, 2019, 12:28pm UTC](https://discourse.processing.org/t/getting-a-strange-error-while-using-shader/12522/5 "2019-07-11T12:28:27Z")

</div>

This is what I was looking for ! That template and docs for integrating shaders in P5 are just awesome !

However, I just noticed that am getting significantly low FPS on Firefox (16-20) compared to Chrome(60). I am making some computations on P5 side. Is P5 hindering FPS on Firefox ?

---

<div class="post-metadata">

**Author:** ![figraham](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/figraham/32/4161_2.png) [@figraham](https://discourse.processing.org/u/figraham)\
**Post date:** [July 11, 2019, 4:32pm UTC](https://discourse.processing.org/t/getting-a-strange-error-while-using-shader/12522/6 "2019-07-11T16:32:29Z")

</div>

I would guess it has to do with the JavaScript engine in firefox rather than something you’re doing. You can read more about it [here](https://www.quora.com/Why-is-WebGL-so-slow-on-Firefox-compared-to-Chrome). I’ve found that the performance of WebGL is very dependent of the device you use, while it often works great on my laptop it hardly works on my old phone.
