Skip to main content

c++ - Boost serialization to XML crashes -


i'm experiencing wierd crash while trying serialize object using boost. interestingly problem occurs when compile project in release mode. in debug mode works fine , xml file written correctly.

here code class supposed serialized. member variable "weights" pointer array dynamically allocated during object construction.

[...] private: [...] int numorientations; int numscales; float thresh; float* weights; friend class boost::serialization::access; template<class archive> void serialize(archive& ar, const unsigned int version) { using boost::serialization::make_nvp; using boost::serialization::make_array; ar & make_nvp("numorient", numorientations); ar & make_nvp("numscales", numscales); ar & make_nvp("thresh", thresh); ar & make_nvp("weights", make_array(weights, numscales*4 + 1)); } 

the whole thing called by:

std::fstream mpbcstr("test.xml", std::fstream::trunc | std::fstream::out); boost::archive::xml_oarchive xml(mpbcstr); <-- program executes fine until here xml << boost::serialization::make_nvp("gpbconfig", configg); <-- not reached mpbcstr.close(); 

since works fine in debug mode. tried pin down location of error printing debug statements after every line. marked lines in code above code crashes. funny thing in serialization function not first line executed before crash.

the error getting is:

 first-chance exception @ 0x000000013f4c31cd in rungpb.exe: 0xc0000005: access violation reading location 0x000000003d4ccccd. 

not helpful, know. suggestions problem appreciated.

c++ - boost serialization xml crashes - stack overflow

learn, share, build

each month, on 50 million developers come stack overflow learn, share knowledge, , build careers.

join world’s largest developer community.

sign up

i'm experiencing wierd crash while trying serialize object using boost. interestingly problem occurs when compile project in release mode. in debug mode works fine , xml file written correctly.

here code class supposed serialized. member variable "weights" pointer array dynamically allocated during object construction.

[...] private: [...] int numorientations; int numscales; float thresh; float* weights; friend class boost::serialization::access; template<class archive> void serialize(archive& ar, const unsigned int version) { using boost::serialization::make_nvp; using boost::serialization::make_array; ar & make_nvp("numorient", numorientations); ar & make_nvp("numscales", numscales); ar & make_nvp("thresh", thresh); ar & make_nvp("weights", make_array(weights, numscales*4 + 1)); } 

the whole thing called by:

std::fstream mpbcstr("test.xml", std::fstream::trunc | std::fstream::out); boost::archive::xml_oarchive xml(mpbcstr); <-- program executes fine until here xml << boost::serialization::make_nvp("gpbconfig", configg); <-- not reached mpbcstr.close(); 

since works fine in debug mode. tried pin down location of error printing debug statements after every line. marked lines in code above code crashes. funny thing in serialization function not first line executed before crash.

the error getting is:

 first-chance exception @ 0x000000013f4c31cd in rungpb.exe: 0xc0000005: access violation reading location 0x000000003d4ccccd. 

not helpful, know. suggestions problem appreciated.

share|improve question
1  
you must have buffer overflow or so. debug builds leave bytes @ end of allocated memory chunks, in order identify such cases. try using valgrind or similar tool. might show exact location of error. – eran jul 7 '12 @ 13:19
    
if turn on debug symbols, can in release mode, should able enter debugger @ point of failure should working out has been corrupted. – alan stokes jul 7 '12 @ 13:26
    
use valgrind or update question complete reproducer – sam miller jul 7 '12 @ 13:27
    
i suspect much. i've tried running program through application verifier , asked friend intel tools installed run through memory debugger. nothing found. – compuholic jul 7 '12 @ 13:28
1  
one obvious question: weights numscales*4+1 elements long ? make_array(weights, numscales*4 + 1) .... , pointer initialized ? – matthieu m. jul 7 '12 @ 13:46

your answer

 
discard

posting answer, agree privacy policy , terms of service.

browse other questions tagged or ask own question.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -