crash in solidworks

Hi guys,

I use the following codes to create splines, when my addin is first time called (say creating 10 splines), it is ok, but if I repeat the call, the solidworks crashes. Could anyone please take a look and give me some hints what I have done wrong?

If I unblock the line "//*** block" (the last line in the attached codes), then the solidworks crashes after call the first time call, the solidworks crashes.

Any help will be appreciated.

best regards

john

///// attached codes:

CComPtr sketch_manager  = NULL;

CComPtr  swModel;
m_iSldWorks->get_IActiveDoc2(&swModel);
swModel->get_SketchManager(&sketch_manager);
sketch_manager->Insert3DSketch(FALSE);

swModel->EditSketch();
sketch_manager->put_AddToDB(TRUE);

CComPtr active_sketch = NULL;
sketch_manager->get_ActiveSketch(&active_sketch);


****save the xyz value to "xyz" and set the pcount.
        **** call the following functions five times.
CComPtr sketch_seg = NULL;
HRESULT rt = sketch_manager->ICreateSpline2(pcount, xyz, FALSE, &sketch_seg);


sketch_manager->put_AddToDB(FALSE);
//*** block  sketch_manager->Insert3DSketch(TRUE);

SolidworksApi macros