matter-js icon indicating copy to clipboard operation
matter-js copied to clipboard

Had a Fatal Error, reason unknown: vertexA is undefined

Open dragonwhites opened this issue 1 year ago • 4 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 avatar Sep 10 '23 10:09 dragonwhites

@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?

aJamDonut avatar Oct 09 '23 18:10 aJamDonut

@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 avatar Oct 09 '23 18:10 dragonwhites

@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.

aJamDonut avatar Oct 10 '23 01:10 aJamDonut

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

aJamDonut avatar Oct 10 '23 01:10 aJamDonut