Boost logo

Boost :

Subject: [boost] invalid null pointer error in serialization with MSVC2008
From: h yh (johann1111_at_[hidden])
Date: 2010-03-15 22:46:58


Hi,

I am getting a very strange runtime error using boost serialization library
with MSVC2008.
I called the following template in my program.

template <class T>
void loadData(std::string fileName, T &t)
{
    std::ifstream ifs(fileName.c_str());
    boost::archive::text_iarchive ia(ifs);
    t.clear();
    ia >> t;
    ifs.close();
}

it gets an assertion failed when running into boost::archive::text_iarchive
ia(ifs);

Debug Assertion failed: invalid null pointer

Here is the stack frame:

msvcr90d.dll!memcpy_s(void * dst=0x00000000, unsigned int
sizeInBytes=4294967295, const void * src=0x07953f63, unsigned int count=22)
Line 55 + 0x2f bytes

msvcp90d.dll!std::char_traits<char>::_Copy_s(char * _First1=0x00000000,
unsigned int _Size_in_bytes=4294967295, const char * _First2=0x07953f63,
unsigned int _Count=22) Line 582 + 0x16 bytes

msvcp90d.dll!std::_Traits_helper::copy_s<std::char_traits<char> >(char *
_First1=0x00000000, unsigned int _Size=4294967295, const char *
_First2=0x07953f63, unsigned int _Count=22, std::_Secure_char_traits_tag
__formal={...}) Line 714 + 0x15 bytes

msvcp90d.dll!std::_Traits_helper::copy_s<std::char_traits<char> >(char *
_First1=0x00000000, unsigned int _Size=4294967295, const char *
_First2=0x07953f63, unsigned int _Count=22) Line 706 + 0x22 bytes

msvcp90d.dll!std::basic_streambuf<char,std::char_traits<char>
>::_Xsgetn_s(char * _Ptr=0x00000000, unsigned int _Ptr_size=4294967295, int
_Count=22) Line 342 + 0x1a bytes

msvcp90d.dll!std::basic_streambuf<unsigned short,std::char_traits<unsigned
short> >::_Sgetn_s(unsigned short * _Ptr=0x00000000, unsigned int
_Ptr_size=4294967295, int _Count=22) Line 118

msvcp90d.dll!std::basic_istream<char,std::char_traits<char> >::_Read_s(char
* _Str=0x00000000, unsigned int _Str_size=4294967295, int _Count=22) Line
698 + 0x27 bytes

msvcp90d.dll!std::basic_istream<char,std::char_traits<char> >::read(char *
_Str=0x00000000, int _Count=22) Line 712

MyProject.exe!boost::archive::text_iarchive_impl<boost::archive::text_iarchive>::load()
+ 0xad bytes

MyProject.exe!loadData<std::set<GamingNote,GamingNote,std::allocator<GamingNote>
> >(std::basic_string<char,std::char_traits<char>,std::allocator<char> >
fileName="nocturne.gnt",
std::set<GamingNote,GamingNote,std::allocator<GamingNote> > & t=[0]()) Line
14 + 0x14 bytes

It happens when the text_iarchive class constructs, so I am sure it's
nothing to do with the serialize function of T, but something between boost
and std::ifstream.

The wierd thing is I didn't come across this program at the first time. It
appears suddenly during development. If I separate the serialization code to
a single cpp file, it doesn't have any problem at all.

By the way, I am intergrating Qt and Ogre with boost by the way, but that
seems not to be quite helpful to identify this problem. Any ideas about
that?

Yuheng Huang


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk