DynamicTree.cs crash

Topics: Developer Forum, User Forum
Jul 5, 2012 at 5:26 PM

Hey.

I have my game running the newest Farseer engine. My game is also multiplayer, and the way I handle synchronizing the game clients is by sending and receiving LinearVelocity vectors and Position vectors and assigning them.

However, it would seem that this rapid changing of the LinearVelocity and Position vectors causes the Farseer engine to throw the cryptic exception about the RemoveLeaf function and whatnot.

Is it the fact that I'm manually changing the Position and LinearVelocity or could it be something else? I've checked the values every time and they are reasonable (Position X: -16,88761 Y: 70,2126 - Velocity X: -3.746503 Velocity Y: 1.22308958 for the very latest crash) and is there something I could do to prevent this?

Jul 6, 2012 at 6:42 AM

Hello, I have the exact same problem.

I managed to get rid of some of the errors by using body.SetTransformIgnoreContacts, and I stopped setting the velocity as well. I actually removed most of the physics from the client, except for controlling the player.

Now every once in a while, the error does seemingly randomly appear. I also get a few Stack Empty errors when the game starts or bodies are created (Mostly when the game starts), which happen in world.step() and BodyFactory methods.

Anyway, I have no real solution to this yet. I'm thinking it's because we're setting position/velocity while the world is updating, and it changes something in the process. Maybe this'll give you some insight.

Jul 7, 2012 at 12:50 PM

Hey, just thought I'd drop by and say that I've fixed my own problem, just in case someone drops by with the same problem.

The cause was that I was creating bodies and updating their position/velocity on a separate thread than the one calling world.step(), just like I thought. I solved this (because I couldn't combine the two threads into one) by adding entities to a list, which serves as a sort of queue. The thread that calls world.step() runs through this list, creating entities before continuing with the step.

Anyway, it was just bad design on my part. Good luck guys!