Forum posts for network.exe

why does VS2013 throw an exception when destroying unique pointer?

Can you provide insight on what this exception means and why it is only thrown when unique_ptr is != nullptr?

Code compiles and runs throwing exceptions.

The unique pointer pFace2 seems to throw an exception when it is being destroyed.
It does not throw an exception when it == nullptr.

The VS2013 exception info is:


First-chance exception at 0x00CA6A0C in Network.exe: 0xC0000005:
Access violation writing location 0xCCCCCCD0.

If there is a handler for this exception, the program may be safely
continued.


Code is:

for (auto volume : domain) {
std::cout << 'Volume ' << volume->getID() << ' ';
for (auto face : volume->volumeFaces) {

auto pNeighbourVolume = std::find_if(
domain.begin(), domain.end(), [&](std::shared_ptr<controlVolume> i) {
return i->getID() == face.getNeighbour();
});

if (pNeighbourVolume != domain.end()) {
std::cout << ' connected to ' << (*pNeighbourVolume)->getID() << ' ';

//This pointer
std::unique_ptr<cvVolumeFace> pFace2 = (*pNeighbourVolume)->matchingFace(face);

std::cout << ' ';
} //<- here is where code breaks
}
std::cout << ' ';
}


the definition for matching type is:

std::unique_ptr<cvVolumeFace> controlVolume::matchingFace(cvVolumeFace &neighboursFace) {
for (auto face : volumeFaces) {
if ((face.getNeighbour() == neighboursFace.getNeighbour()) &&
(face.getArea() - neighboursFace.getArea() < face.matchTolerence())) {
std::cout << 'Matched faces for ' << face.getNeighbour() << ' and ' << neighboursFace.getNeighbour();
std::unique_ptr<cvVolumeFace> pFace(&face);
return pFace;
}
}
std::cout << 'ERROR: No matching face to return! ';
return nullptr;
};


The break occurs in memory.h at line 116

void _Decref()
{ // decrement use count
if (_MT_DECR(_Mtx, _Uses) == 0) //<-breaks here
{ // destroy managed resource, decrement weak reference count
_Destroy();
_Decwref();
}
}

View complete forum thread with replies

Other posts related to network.exe

See Related Forum Messages: Follow the Links Below to View Complete Thread

why does VS2013 throw an exception when destroying unique pointer?

What is the carbon footprint of your coffee?

Is it low? Is it high? Can this things really kill the planet Earth? Maybe the answer will surprise you. Maybe not.