Debug Assertion Failed dbgdel.cpp error

M

marat

I have a managed c++ function below that makes a call to an unmanaged c++ dll
.. This function is called from a C# app, resulting in a

"Debug Assertion Failed dbgdel.cpp Line 52
Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)" errir message.

This happens on function exit, looks like related to destruction of some vector.

Any ideas why ????


ArrayList*
NM::doSomething(ArrayList* anchorStrikesList,
ArrayList* anchorVolsList,
ArrayList* allStrikesList

{
vector<double> anchorStrikesVec, anchorVolsVec, allStrikesVec, allVolsVec;

////// convert to vectors ////

for (int i = 0; i < anchorStrikesList->Count; ++i)
{
double val = *dynamic_cast<double __gc *>(anchorStrikesList->get_Item(i));
anchorStrikesVec.push_back(val);
}
for (i = 0; i < anchorVolsList->Count; ++i)
{
double val = *dynamic_cast<double __gc *>(anchorVolsList->get_Item(i));
anchorVolsVec.push_back(val);
}
for (i = 0; i < allStrikesList->Count; ++i)
{
double val = *dynamic_cast<double __gc *>(allStrikesList->get_Item(i));
allStrikesVec.push_back(val);
}

// unmanaged c++ dll call
foo(anchorStrikesVec, anchorVolsVec, allStrikesVec, allVolsVec);

// Convert back to vector of computed vols and return
ArrayList* allVolsList = new ArrayList();
for (i = 0; i < allVolsVec.size(); ++i)
{
double vol = allVolsVec;
allVolsList->Add(__box(vol));
}
return allVolsList;

}
 
M

marat

The problem appears to occur due to the unmanaged foo() call's last
argument which is a non const reference to a vector.

The prototype of foo is :

void foo(const vector<double>& l1,
const vector<double>& l2,
const vector<double>& l3,
vector<double>& result);

If result vector is empty, no problem occurs.
If non-empty then the below error occurs.

The last argument needs to be non const.

Anyone know how to solve this one ?
ArrayList*
NM::doSomething(ArrayList* anchorStrikesList,
ArrayList* anchorVolsList,
ArrayList* allStrikesList

{
vector<double> anchorStrikesVec, anchorVolsVec, allStrikesVec, allVolsVec;

////// convert to vectors ////

for (int i = 0; i < anchorStrikesList->Count; ++i)
{
double val = *dynamic_cast<double __gc *>(anchorStrikesList->get_Item(i));
anchorStrikesVec.push_back(val);
}
for (i = 0; i < anchorVolsList->Count; ++i)
{
double val = *dynamic_cast<double __gc *>(anchorVolsList->get_Item(i));
anchorVolsVec.push_back(val);
}
for (i = 0; i < allStrikesList->Count; ++i)
{
double val = *dynamic_cast<double __gc *>(allStrikesList->get_Item(i));
allStrikesVec.push_back(val);
}

// unmanaged c++ dll call
foo(anchorStrikesVec, anchorVolsVec, allStrikesVec, allVolsVec);

// Convert back to vector of computed vols and return
ArrayList* allVolsList = new ArrayList();
for (i = 0; i < allVolsVec.size(); ++i)
{
double vol = allVolsVec;
allVolsList->Add(__box(vol));
}
return allVolsList;

}
 
Top