SetTarget and for loops?

For anyone interested, I finally solved this problem with the help of a friend.

The original code was:
Code:
        //run physics
        for (int32 i = 0;i<10;++i)
        {
            b2MouseJoint* dotDrag;
            if(timeMode==play$)
            {


                //deal with mouse dragging
                if(mouseDrag)
                {
                    b2MouseJointDef dotDragDef;
                    dotDragDef.body1 = world.GetGroundBody();
                    dotDragDef.body2 = dotPhysics.at(dotCount);
                    dotDragDef.timeStep = timeStep;
                    dotDragDef.dampingRatio = 0;
                    dotDragDef.frequencyHz = 60.0;
                    dotDragDef.target.Set(pointerPos.x, pointerPos.y);
                    dotDragDef.maxForce = 100000.0f;

                    if(dragOn)
                    {
                        dotDrag->SetTarget(pointerPos);
                    }
                    else
                    {
                        dotDrag = static_cast<b2MouseJoint*>(world.CreateJoint(&dotDragDef));
                        dragOn = true;
                    }
                }
                else if(dragOn)
                {
                    hold(dotPhysics.at(dotCount));
                    world.DestroyJoint(dotDrag);//could cause a problem later if not all dotDrag joints are destroyed...
                    dragOn = false;
                }
                world.Step(timeStep, iterations);

            }
        }


The problem was that the b2MouseJoint declaration was inside the for loop. The problem disappeared when the declaration was moved outside of the for loop like so:

Code:
b2MouseJoint* dotDrag;
        //run physics
        for (int32 i = 0;i<10;++i)
        {
            if(timeMode==play$)
            {


                //deal with mouse dragging
                if(mouseDrag)
                {
                    b2MouseJointDef dotDragDef;
                    dotDragDef.body1 = world.GetGroundBody();
                    dotDragDef.body2 = dotPhysics.at(dotCount);
                    dotDragDef.timeStep = timeStep;
                    dotDragDef.dampingRatio = 0;
                    dotDragDef.frequencyHz = 60.0;
                    dotDragDef.target.Set(pointerPos.x, pointerPos.y);
                    dotDragDef.maxForce = 100000.0f;

                    if(dragOn)
                    {
                        dotDrag->SetTarget(pointerPos);
                    }
                    else
                    {
                        dotDrag = static_cast<b2MouseJoint*>(world.CreateJoint(&dotDragDef));
                        dragOn = true;
                    }
                }
                else if(dragOn)
                {
                    hold(dotPhysics.at(dotCount));
                    world.DestroyJoint(dotDrag);//could cause a problem later if not all dotDrag joints are destroyed...
                    dragOn = false;
                }
                world.Step(timeStep, iterations);

            }
        }

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