setting b2EdgeChainDef points and adding to world

Hi,

Hopefully this will be easy for someone more knowledgeable in c++ and boxd2 than me to answer, I'm quite new so struggling a bit. Basically I'm trying to set the vertices in a b2EdgeChainDef from a vector of points created elsewhere, then add it to my box2d world. This my code:

Code:
b2EdgeChainDef* edgeDef = new b2EdgeChainDef();            

            vector<ofPoint> points = contourFinder.blobs[0].pts;         //vector of points   
         
            edgeDef->vertices = new b2Vec2[points.size()];
            for(int j=0; j < points.size(); j++){               
               edgeDef->vertices[j].Set(points[j].x,points[j].y);               
            }
            //float scaleX = (float) ofGetWidth() / (float)grayDiff.width;
            //float scaleY = (float) ofGetHeight() / (float)grayDiff.height;
            
            edgeDef->isALoop = true;
            edgeDef->density = 3.0f;
            edgeDef->restitution = 1.0f;
            edgeDef->vertexCount = edgeDef->vertices->Length();
            //edgeDef.vertices = verts;

            box2d.getWorld()->GetGroundBody()->CreateShape(edgeDef);

            delete [] edgeDef->vertices;  // When done, free memory pointed to by a.
            edgeDef->vertices = NULL;


It compiles fine but when I run it it crashes with a debug error. If anyone could help that would be amazing.

Thanks, adam

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