Question

I'm trying to use a std::vector<>::const_iterator and I get an 'access violation' crash. It looks like the std::vector code is crashing when it uses its own internal First_ and Last_ pointers. Presumably this is a known bug. I'm hoping someone can point me to the correct workaround. It's probably relevant that the crashing function is called from an external library?

const Thing const*  AClass::findThing (const std::string& label) const
{
    //ThingList_.begin() blows up at run time.  Compiles fine.
    for (std::vector<Thing*>::const_iterator it = ThingList_.begin(); it != ThingList_.end(); ++it) {
        //Irrelevant.
    }
    return 0;
}

Simply calling ThingList_.size() also crashes.

This is sp6, if it matters.

Was it helpful?

Solution

If you're passing C++ objects across external library boundaries, you must ensure that all libraries are using the same runtime library (in particular, the same heap allocator). In practice, this means that all libraries must be linked to the DLL version of MSVCRT.

OTHER TIPS

It's almost certainly a bug in your code and not std::vector. This code is used by way too many projects to have such an easy to repro bug.

What's likely happening is that the ThnigList_ variable has been corrupted in some way. Was the underlying array accessed directly and/or modified?

I agree with Jared that it is probably in your code, never the less, you should be sure your stl libs are up to date.

The dinkumware site has the patched files you need.

You should update just to be safe

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top