# Cannot read property 'subtractToRef' of undefined

**URL:** <https://forum.babylonjs.com/t/cannot-read-property-subtracttoref-of-undefined/11955>\
**Category:** Bugs\
**Created:** [June 24, 2020, 1:43am UTC](https://forum.babylonjs.com/t/cannot-read-property-subtracttoref-of-undefined/11955 "2020-06-24T01:43:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![phenry20](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/phenry20/32/8117_2.png) [@phenry20](https://forum.babylonjs.com/u/phenry20)\
**Post date:** [June 24, 2020, 1:43am UTC](https://forum.babylonjs.com/t/cannot-read-property-subtracttoref-of-undefined/11955/1 "2020-06-24T01:43:20Z")

</div>

Hi,

With some models I get the following error when trying to move the camera with my mouse

```auto
ray.ts:188 Uncaught TypeError: Cannot read property 'subtractToRef' of undefined
    at Ray.intersectsTriangle (ray.ts:188)
    at SubMesh._intersectTriangles (subMesh.ts:490)
    at SubMesh.intersects (subMesh.ts:408)
    at Mesh.AbstractMesh.intersects (abstractMesh.ts:1497)
    at Scene.push../node_modules/@babylonjs/core/Culling/ray.js._scene __WEBPACK_IMPORTED_MODULE_4__.Scene._internalPick (ray.ts:680)
    at Scene.push../node_modules/@babylonjs/core/Culling/ray.js._scene __WEBPACK_IMPORTED_MODULE_4__.Scene.pick (ray.ts:738)
    at HTMLCanvasElement._onPointerDown (scene.inputManager.ts:661)

```

I tried recreating it in a playground, but I wasn’t able to recreate it which leads me to believe that it’s a lifecycle issue issue in React or a BabylonJS engine issue.

Is anybody able to give me a hint to lead me in the right direction?

---

<div class="post-metadata">

**Author:** ![phenry20](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/phenry20/32/8117_2.png) [@phenry20](https://forum.babylonjs.com/u/phenry20)\
**Post date:** [June 24, 2020, 5:03am UTC](https://forum.babylonjs.com/t/cannot-read-property-subtracttoref-of-undefined/11955/2 "2020-06-24T05:03:07Z")

</div>

~~Update: I found a similar issue ([Error when clicking on point-cloud mesh without indices](https://forum.babylonjs.com/t/error-when-clicking-on-point-cloud-mesh-without-indices/2895)), but there was no mention of what the fix was. Maybe it’s related to that?~~

 

Also I realized that this issue usually occurs when clicking on the model when trying to rotate the camera. Even though my playground doesn’t reproduce the error, it should give you an idea of what my code is doing.

[https://www.babylonjs-playground.com/#KM2N07#20](https://www.babylonjs-playground.com/#KM2N07#20)

~~Lastly I should mention that I’m using views since I’m using multiple canvases so maybe that has something to do with it~~

Nevermind I figured it out. It was an oversight. The crash was caused by this line in my code:

```auto
scene.clearCachedVertexData();
scene.cleanCachedTextureBuffer();

```

I add those 2 lines to reduce the memory footprint as per the documentation ([Reduce memory footprint - Babylon.js Documentation](https://doc.babylonjs.com/how_to/reduce_memory_footprint)), but I didn’t realize it would cause this error.
