setting ofxBox2d b2EdgeChainDef points and adding to world

Hi,

I am currently trying to create a ofxBox2d b2EdgeChainDef and setting it’s vertices from a vector of points from a contour blob found using ofxOpenCV, then add it in the correct position in my ofxBox2d world and have it so it updates on each frame. The following code in my update() function compiles fine but when I run it, it always crashes and returns a debug error message:

  
b2EdgeChainDef edgeDef;		  
				vector<ofPoint> points = contourFinder.blobs[0].pts;				  
			  
				edgeDef.vertices = new b2Vec2[points.size()];  
  
				for(int j=0; j < points.size(); j+=10){					  
					edgeDef.vertices[j].Set(points[j].x,points[j].y);					  
				}  
				  
				edgeDef.isALoop = true;  
				edgeDef.density = 3.0f;  
				edgeDef.restitution = 1.0f;  
				edgeDef.vertexCount = edgeDef.vertices->Length();  
				  
				b2BodyDef bodyDef;  
				bodyDef.position.Set(10.0f, 4.0f);  
				b2Body* body = box2d.world->CreateBody(&bodyDef);  
				body->CreateShape(&edgeDef);  
				body->SetMassFromShapes();  
  
  
				delete [] edgeDef.vertices;    
				edgeDef.vertices = NULL;  

I’ve already seen http://forum.openframeworks.cc/t/blob-contour-to-box2d-b2edgechaindef/2347/0 but still cant get it working. Any help very much appreciated or ideally an example from someone has managed to do this!

Thanks, Adam