schteppe / p2.js

JavaScript 2D physics library
Other
2.64k stars 330 forks source link

IslandManager - Cannot read property 'neighbors' of undefined #223

Closed hapticdata closed 8 years ago

hapticdata commented 8 years ago

Hello,

I am running into an issue where periodically an error is thrown in IslandManager#split(world) on line 168. Occasionally bodies.indexOf(eq.bodyB) is returning -1. It appears to happen when I have created a very-large shape.

My scene is basically 2 planes for sides and a floor that I periodically remove and then remove any bodies that have fallen below the floor.

thanks for all of your hard work, p2.js is great!

schteppe commented 8 years ago

Hi, The easy way is to set world.islandSplit to false and this should not happen. Do you have constraints on the bodies you remove? Then you need to remove the constraints first.

schteppe commented 8 years ago

Also, do you use the collision events to remove bodies? Try doing the removal in the update loop instead. See https://github.com/schteppe/p2.js/pull/208#issuecomment-184023675

hapticdata commented 8 years ago

Thanks, world.islandSplit = false worked for my use case. The bodies do have constraints on them. I was removing them in the update loop. I was removing the bodies before the constraints, but they were sequential operations. Maybe that was it.

thanks so much!