b2DistanceJoint results in crazy movement

Okay. I have a series of movieclips, each one containing a collideObj instance which references a b2BodyDef. I use them to arrange a scene in the IDE and then loop through them and add them to the world, and replace the collideObj definitions with the resulting b2Bodys. This works great, but now I'm trying to add joints. Each joint movieclip is a line with an invisible mc at each end. This is how I translate them into b2DistanceJointDefs:
Code:
      public function initJoints(){
         for(var i=0;i<numChildren;i++){
            trace(i)
            child = getChildAt(i)
            if (child.collideObj is b2DistanceJointDef){
//               trace("Found joint",child);
               var joint = child.collideObj
               var end1 = child.getChildByName("end1") //These sit at the ends of the line segment
               var end2 = child.getChildByName("end2")
               var pt1 = new Point(end1.x,end1.y);
               var pt2 = new Point(end2.x,end2.y);
               
               trace(end2.x,end2.y)
               
               pt1 = child.localToGlobal(pt1); //Where are we actually?
               pt2 = child.localToGlobal(pt2);
               for(var j in platforms){ //Loop through all movieclips that hold b2Body refs
                  trace("finding collided...");
                  trace(platforms[j]);
                  if(platforms[j].hitTestPoint(pt1.x,pt1.y)){ //If the left endpoint is hitting this body
                     trace(platforms[j])
                     joint.body1 = platforms[j].collideObj;
                     pt1 = platforms[j].globalToLocal(pt1);//Find where it is hitting relative to the body
                     trace(pt1.x,pt1.y);
                     joint.anchorPoint1 = new b2Vec2(pt1.x*.1,pt1.y*.1);
                  } else if (platforms[j].hitTestPoint(pt2.x,pt2.y)){
                     joint.body2 = platforms[j].collideObj;
                     pt2 = platforms[j].globalToLocal(pt2)
                     joint.anchorPoint2 = new b2Vec2(pt2.x*.1,pt2.y*.1); //*.1 is the scale factor
                  }
               }
               child.collideObj = joint;
               joints.push(joint);
            }
         }
//         trace(joints.length);
      }

The joints are added to the scene in a different class:
Code:
         var joints = collision.joints
         for(var i in joints){
            m_world.CreateJoint(joints[i]);
         }


If I connect a static with a dynamic body, the dynamic one goes crazy, flickering all over the place apparently at random. If I connect two dynamic bodies together, they flicker around a bit and disappear. Is there anything wrong with what I've done to set the b2DistanceJointDefs? If I set the anchorPoints to 0,0 the same effect occurs. I should say that I'm still using 1.4.3, because I don't want to jump horses midstream (at least not quite yet).
I've had bodies jitter and go crazy when I've scaled them too large and perhaps also set a high density. Not sure if this is what is happened for you.
A.Russell wrote:
I've had bodies jitter and go crazy when I've scaled them too large and perhaps also set a high density. Not sure if this is what is happened for you.

I'm pretty sure the density etc is just fine, the bodies behave perfectly by themselves, it's only when I try to connect them with joints that odd things happen.

Tracing the body's x,y returns this:
Code:
258.0736442802523 -4.754536667863792
125.74891725286375 -453.2000011617434
303.0451010348537 0.6613953310154552
125.74891725286375 -453.2000011617434
303.79665086330846 -4.5314267621868165
125.74891725286375 -453.2000011617434
326.8732584675644 -16.793869225280503
125.74891725286375 -453.2000011617434
327.6519072483801 -22.517863485220232

etc.
Please check this post: http://www.box2d.org/forum/viewtopic.php?f=8&t=923
Maybe it is the same problem, that I have got with b2DistanceJoint.
sethodie wrote:
Please check this post: http://www.box2d.org/forum/viewtopic.php?f=8&t=923
Maybe it is the same problem, that I have got with b2DistanceJoint.


I don't think it's that problem, because those two lines look correct in the 1.4.3 source.

So the object really is flying back and forth crazily each frame. The very first frame is perfect, but as soon as the simulation steps again it's gone God knows where. And then it goes back, and away, and back. It shouldn't be moving at all, nothing is touching it (it's set up like a pendulum pointed straight down). I might try switching to 2.0.1, this is really very frustrating.
Code:
39.59501811972412 45.54684383301239
146.33 48.91187500000001
39.5950454959006 45.6405465190192
146.33 49.00562500000001
39.5950511957546 45.781119613955816
146.33 49.14625000000001
39.5948302743726 45.968391752438784
146.33 49.33375000000001
25.122076103097108 28.218143312979333
146.33 49.56812500000001
24.95335112279947 28.58065909235867
146.33 49.84937500000001
13.417295214233064 7.9002104921724285
146.33 50.17750000000001
13.607629849440082 8.703782100182988


Edit: Aha. 1.4.3 defines joints in global coords, 2.0 in local, and I'd been reading the 2.0 docs. Whoops.

Original thread: https://box2d.org/forum/viewtopic.php?t=952