Robert Ramey writes:
I don't see any problem with the code snippet. Maybe you want
to make small test which we run here.
ok here it comes. It looks artificial, but it is just a simplification of a
case. It gives an access violation after thhe load, when it tries to destroy
the object.
#include
namespace
{
struct BoostExampleData
{
BoostExampleData()
: m_i(0)
{}
template <class Archive>
void serialize(Archive& ar, const unsigned int /*version*/)
{
ar & BOOST_SERIALIZATION_NVP(m_i);
}
public: //data
int m_i;
};
struct BoostExample
{
BoostExample()
{
m_ptr.reset(new BoostExampleData);
m_ptr1.reset(new BoostExampleData);
}
template <class Archive>
void serialize(Archive& ar, const unsigned int /*version*/)
{
ar & BOOST_SERIALIZATION_NVP(m_ptr);
ar & BOOST_SERIALIZATION_NVP(m_ptr1);
}
public: //data
typedef boost::shared_ptr<BoostExampleData> Ptr;
Ptr m_ptr;
Ptr m_ptr1;
};
}
void Test()
{
BoostExample obj;
std::stringstream sstr;
//save
boost::archive::xml_oarchive oa(sstr);
oa << BOOST_SERIALIZATION_NVP(obj);
//triggers a load exception
std::string str = sstr.str();
boost::replace_all(str, "", "> BOOST_SERIALIZATION_NVP(obj);
}
catch (boost::archive::archive_exception& /*re*/)
{
ia.delete_created_pointers();
}
}
catch (boost::archive::archive_exception& /*re*/)
{
}
}
wkr,
me