Boost Serialization Segfault

夙愿已清 提交于 2019-12-02 04:14:49

You just need to initialize the data in your data structures. All primitive types that haven't been explicitely initialized will have indeterminate ("random") values. This includes the pointers, which means you're invoking Undefined Behaviour by dereferencing pointers to random memory locations.

Here's an update with the simplest initialization that could possibly work, and it runs clean under Valgrind. That's a good tool. Use it!

Also, crank up the compiler messages (-Wall -Wextra -pedantic at a minimum for gcc/clang).

Added in various places:

Data() : id_x_(0), id_y_(0), id_z_(0), lin_id_(0), num_points_(0), user_data_(0)
{
    std::fill(n_, n_+3, 0);
    std::fill(p_, p_+3, 0);
}
Node() : data_(0), radius_(0), parent_(0), children_(0) 
{
    std::fill(center_, center_+3, 0);
    std::fill(bounds_, bounds_+6, 0);
}
ORROctree() : voxel_size_(0), tree_levels_(0), root_(0)
{
    std::fill(bounds_, bounds_+6, 0);
}
NDIMVoxelStructure() : voxels_(0), total_num_of_voxels_(0) 
{ }
Base() : seg1(0, 0), seg2(0, 0) 
{ }

See it Live On Coliru

Update From the comment: the following lines were clearly in error:

inline void serialize(Archive & ar, ORROctree::Node n, const unsigned int version)
inline void serialize(Archive & ar, ORROctree::Node::Data d, const unsigned int version)

And should have read

inline void serialize(Archive & ar, ORROctree::Node& n, const unsigned int version)
inline void serialize(Archive & ar, ORROctree::Node::Data& d, const unsigned int version)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!