Strange error with distance joints!

I've been having odd issues with my application crashing recently when using a lot of distance joints.
after running for awhile i get:

"pure virtual method called
terminate called without an active exception"


I'm not sure where the problem is, whether it's in my code or box2d.

When running in valgrind i get

==18150== Conditional jump or move depends on uninitialised value(s)
==18150== at 0x804D467: CBox::update(float) (cbox.cpp:644)
==18150== by 0x8056E10: CWorld::update(float) (cworld.cpp:879)
==18150== by 0x804B13A: simulate(float) (main.cpp:439)
==18150== by 0x804CEA6: main (main.cpp:700)

Code:
         b2JointEdge *j = bBody->GetJointList();
         while(j) {
            b2JointEdge *next = j->next;
            if(j->joint) {
               if(j->joint->GetType() == e_distanceJoint) {
                  b2Vec2 force = j->joint->GetReactionForce(60.0f);
                  float flength2 = 0.0f;
cbox:644 >>>                  flength2 = force.LengthSquared();
                  if(flength2 > 64.0f) {
                     world->bWorld->DestroyJoint(j->joint);
                     j->joint = NULL;
                  }
               }
            }
            j = next;
         }



and just as it crashes...

==18409== Invalid free() / delete / delete[]
==18409== at 0x40212EC: operator delete(void*) (vg_replace_malloc.c:342)
==18409== by 0x806DCDD: b2Island::Solve(b2TimeStep const&, b2Vec2 const&, bool) (b2Island.cpp:249)
==18409== by 0x805F90A: b2World::Solve(b2TimeStep const&) (b2World.cpp:429)
==18409== by 0x8060288: b2World::Step(float, int, int) (b2World.cpp:822)
==18409== by 0x8055BB3: CWorld::update(float) (cworld.cpp:658)
==18409== by 0x804B13A: simulate(float) (main.cpp:439)
==18409== by 0x804CEA6: main (main.cpp:700)
==18409== Address 0x6efcdec is 4 bytes inside a block of size 4,100 alloc'd
==18409== at 0x4021AB8: malloc (vg_replace_malloc.c:207)
==18409== by 0x806868A: b2Alloc(int) (b2Settings.cpp:33)
==18409== by 0x80684A6: b2BlockAllocator::Allocate(int) (b2BlockAllocator.cpp:128)
==18409== by 0x805F613: b2World::CreateBody(b2BodyDef const*) (b2World.cpp:104)
==18409== by 0x804F392: CBox::CreateBody() (cbox.cpp:208)
==18409== by 0x80586A5: CCrane::spawnBox() (ccrane.cpp:412)
==18409== by 0x8059947: CCrane::update(float) (ccrane.cpp:499)
==18409== by 0x8056E37: CWorld::update(float) (cworld.cpp:883)
==18409== by 0x804B13A: simulate(float) (main.cpp:439)
==18409== by 0x804CEA6: main (main.cpp:700)

pure virtual method called
terminate called without an active exception

252 // Solve velocity constraints.
253 for (int32 i = 0; i < step.velocityIterations; ++i)
254 {
255 for (int32 j = 0; j < m_jointCount; ++j)
256 {
257 m_joints[j]->SolveVelocityConstraints(step);
258 }
259
260 contactSolver.SolveVelocityConstraints();
261 }
(gdb) print *m_joints[j]
$1 = {_vptr.b2Joint = 0x8073608, m_type = e_distanceJoint, m_prev = 0x6efcf2c, m_next = 0x7a0aa14, m_node1 = {other = 0x7b015b4, joint = 0x6efcdec, prev = 0x6efcf3c, next = 0x0}, m_node2 = {other = 0x7a0a794,
joint = 0x6efcdec, prev = 0x6efcf4c, next = 0x73fafbc}, m_body1 = 0x7a0a794, m_body2 = 0x7b015b4, m_islandFlag = true, m_collideConnected = true, m_userData = 0x0, m_localCenter1 = {x = 0,
y = -0.0160620976}, m_localCenter2 = {x = 0.127093762, y = 0.000725303136}, m_invMass1 = 0, m_invI1 = 0, m_invMass2 = 0, m_invI2 = 2.56728701e-34}

It seems like the joint is losing it's identity as a b2DistanceJoint... i'm not sure how that could happen.?

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