liabru / matter-js

a 2D rigid body physics engine for the web ▲● ■

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Had a Fatal Error, reason unknown: vertexA is undefined

dragonwhites opened this issue · comments

version 0.18.0
This error is very rare since I think it might occur the first time after 2 years of deployment:

TypeError: Cannot read property 'index' of undefined
at Object.Collision._findSupports (/root/sfio2-gameserver/node_modules/matter-js/build/matter.js:4101:54)
at Collision.collides (/root/sfio2-gameserver/node_modules/matter-js/build/matter.js:3928:35)
at Object.Detector.collisions (/root/sfio2-gameserver/node_modules/matter-js/build/matter.js:5599:45)
at Object.Engine.update (/root/sfio2-gameserver/node_modules/matter-js/build/matter.js:8040:35)

The undefined variable is the vertexA of the Collision._findSupports function.
I do not know what is causing the error or if it is fixed in version 0.19.0

@dragonwhites I've also just started to get this issue while refactoring some code. I do think it's my code, but all the bodies do seem correct. But did you find a fix in the end?

@dragonwhites I've also just started to get this issue while refactoring some code. I do think it's my code, but all the bodies do seem correct. But did you find a fix in the end?

I do not find the fix, since I can't replicate the issue and it's super rare, I just updated the library to 0.19 and hope for the best.... May I know what is your library version?

@dragonwhites I've also just started to get this issue while refactoring some code. I do think it's my code, but all the bodies do seem correct. But did you find a fix in the end?

I do not find the fix, since I can't replicate the issue and it's super rare, I just updated the library to 0.19 and hope for the best.... May I know what is your library version?

Version: * matter-js 0.19.0 in UMD format

I've managed to resolve my issue now, I'm pretty sure the issue isn't caused by matter per-se or by bodies you've added to the system, more when applying changes to existing bodies, that are malformed changes.

In my case, when re-loading a file, the Body.setAngle() function was the root cause to this issue. Inside this function it recalculates the vertices, which I had passed a bad value to.

Good luck if it pops up, one recommendation I have is if it seems like all the bodies are fine, instead look at changes you're making to your bodies, angle, size etc.

On another note it appears setAngle (and so I assume others) has no checks for any of the values passed and so no type safety there, in my case I passed NaN