WeldJoint Problems

Topics: Developer Forum, User Forum
Jun 22, 2010 at 6:05 PM
Edited Jun 22, 2010 at 6:06 PM

I am using WeldJoints to connect all the bodies to an enemy. This is the code:

 

            foreach (Body body in addiBodies[0])
            {
                //Create and add weldJoint to world

                //RevoluteJoint tempJoint = new RevoluteJoint(mainBody, body, Vector2.Zero);
                WeldJoint tempJoint = new WeldJoint(mainBody, body, Vector2.Zero);
                Farseer.World.Add(tempJoint);
            }

After about five- ten seconds of gameplay, it freezes. I have changed this code to comment the WeldJoint line and use the RevoluteJoint line and nothing crashes so I'm not sure what I'm doing wrong. I mean I could just use a RevoluteJoint and then set a fixed rotation to each body. That would get what I want done as well. Just trying to figure out how to use WeldJoint.

 

Jun 25, 2010 at 11:33 PM

Can anyone help me out here?

Jun 26, 2010 at 3:08 AM

Do you mean the bodies freeze or the game freezes?

If it's the bodies freezing try disabling Sleeping in the World. I had a problem with joints and Sleeping a while ago, it could be a related issue

Jun 27, 2010 at 7:39 AM

It's the world that freezes. I'm not sure what is going on. Hope it doesn't have to do with sleeping because I have to be able to have bodies sleep in gameplay. It was the main reason I switched to FP3.

Jun 27, 2010 at 9:43 AM

It doesn't sound like the problem I had with sleeping, so you're probably safe in that respect, but try turning it off anyway just to make certain. If it is a bug it will probably be fixed quickly once found.

Make sure you don't have any try/catches in your code that might be ignoring an error. I've done that before and the same thing happened: the world froze and I had no way of knowing there had been an error. A quick search for "try" should help you out there.

Also make sure you're in Debug mode, so that Farseer can run all it's Asserts.

Jun 28, 2010 at 5:15 AM
Edited Jun 28, 2010 at 5:15 AM
I was doing something very similar with joints in my game's update method. The problem was that it was creating joints endlessly, and never removing the previous joints and/or never stopping creating new joints each pass. Could that be what is happening in yours as well? Why not use a global variable for the joints and just use/reuse them, rather than creating new joints each time. To me it sounds like it is taking 5-10 seconds before your computer can't handle that many items in the world anymore, then it freezes. Is this FP3? I've noticed FP3 freeze rather than crash like FP2.x would have.
Jun 28, 2010 at 4:12 PM
Edited Jun 28, 2010 at 8:42 PM

I'll check what you said Jerky but wouldn't it still crash if I switched WeldJoint to RevoluteJoint? Because when I do that, the game runs fine.

 

            foreach (Body body in addiBodies[0])
            {
                //Create and add weldJoint to world

                RevoluteJoint tempJoint = new RevoluteJoint(mainBody, body, Vector2.Zero);
                Farseer.World.Add(tempJoint);
            }

 

I still checked it just to be sure by looking at the number of joints in the World list on the first update and then how many there are 20 updates later (just before it freezes). There are the exact same amount of joints in the list. I also looked at the comparison when switching between RevoluteJoint and WeldJoint. I didn't see anything noticeable. They both have about the same update times.

 

@robertdodd

I currently have not implemented any try, catch statements with my code. Maybe not the smartest thing to do but I was planning on looking into all of that once I'm near the end of my game. I have been running in Release mode though and switched over to Debug mode but it's still freezing and no exceptions are being called or anything. 

 

UPDATE

There are about 1700 contacts when the game just completely lags. I looked into where these contacts are occurring and it's always with some sort of ground (static) body. I know this because anything in CollisionCategory Cat10 is a ground body. Even more is that I looked into the other contact collision and it always has a position of Vector2(NaN, NaN). It is not the same ground fixture everytime either but it is always a ground fixture from what I've seen. There are way too many contacts to look through each one but these are my findings after looking through about 12-15 contacts. Let me add that the first 50 or so contacts look pretty normal. Everything after that has positions of NaN.

 

For now I'm just changing them to RevoluteJoints and setting their rotation as fixed. Quick fix. But if anyone finds out why this doesn't work or when it finally does work, please let me know.

Jul 1, 2010 at 6:56 AM

There is a difference between the constructor of the RevoluteJoint and the WeldJoint.

The anchor in the RevoluteJoint's constructor is the LocalAnchor of BodyB, while the anchor in the WeldJoint constructor is the world position where the 2 bodies get joined, so try this:

tempjoint = new WeldJoint(mainbody, body, body.GetWorldPoint(Vector2.Zero));

I think ideally all joints should use the same system for anchors, so I'm gonna make this into an issue