liabru / matter-js

a 2D rigid body physics engine for the web ▲● ■
MIT License
16.87k stars 1.97k forks source link

Had a Fatal Error, reason unknown: vertexA is undefined #1242

Open dragonwhites opened 1 year ago

dragonwhites commented 1 year ago

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

aJamDonut commented 1 year ago

@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 commented 1 year ago

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

aJamDonut commented 1 year ago

@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 commented 1 year ago

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