gpt4 book ai didi

c++ - 我在使用 boost::serialization 时遇到一个问题,我的代码在 linux 中运行良好,但在 windows 中遇到异常

转载 作者:行者123 更新时间:2023-11-30 04:56:43 24 4
gpt4 key购买 nike

我正在尝试使用 boost 保存由 ORB-SLAM 构建的 map ,该代码在 linux 中运行良好,但是当我将其移动到 windows 时,我在加载数据时遇到了异常。下面是我的部分代码,项目比较大,所以只展示相关代码。

.h中的部分代码

    friend class boost::serialization::access;

template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
boost::serialization::split_member(ar, *this, version);
}

template<class Archive>
void save(Archive & ar, const unsigned int version) const;


template<class Archive>
void load(Archive & ar, const unsigned int version);

CPP简介

        template<class Archive>
void Map::load(Archive & ar, const unsigned int version)
{
unsigned int test_data;

int nItems;
ar & nItems;
cout << "{INFO}mspMapPoints size = " << nItems << endl;

for (int i = 0; i < nItems; ++i) {

MapPoint* pMapPoint = new MapPoint();
ar & *pMapPoint;
mspMapPoints.insert(pMapPoint);
}

ar & nItems;
cout << "{INFO}mspKeyFrames size = " << nItems << endl;

for (int i = 0; i < nItems; ++i) {

KeyFrame* pKeyFrame = new KeyFrame;
ar & *pKeyFrame;
mspKeyFrames.insert(pKeyFrame);
}


ar & nItems;
cout << "{INFO}mvpKeyFrameOrigins size = " << nItems << endl;

for (int i = 0; i < nItems; ++i) {

KeyFrame* pKeyFrame = new KeyFrame;
ar & *pKeyFrame;
/* TODO : VerifyHere*/
mvpKeyFrameOrigins.push_back(*mspKeyFrames.begin());
}

ar & const_cast<long unsigned int &> (mnMaxKFid);

ar & test_data;
if (test_data == TEST_DATA)
cout <<">>Map Loading Validated as True" << endl;
else
cout <<"ERROR Map Loading Validated as False: Got -" << test_data << " :( Check Load Save sequence" << endl;

}

调用函数如下:

void System::LoadMap(const string &filename)
{
{
std::ifstream is(filename,std::ios::binary);


boost::archive::binary_iarchive ia(is, boost::archive::no_header);
//ia >> mpKeyFrameDatabase;
ia >> mpMap;

}

cout << endl << filename <<" : Map Loaded!" << endl;


}
void System::SaveMap(const string &filename)
{
std::ofstream os(filename,std::ios::binary);
{
boost::archive::binary_oarchive oa(os, boost::archive::no_header);
//oa << mpKeyFrameDatabase;
oa << mpMap;
}
cout << endl << "Map saved to " << filename << endl;

}

Linux下保存和加载都可以,但是加载只会抛出boost::archive::archive_exception问题,没有告诉我任何细节。

最佳答案

您应该只显示相关代码。特别是,它应该显示您的存档选择。另外,您从未告诉我们/what/不起作用,但我的猜测是您正在加载保存在 Windows 端的 Linux 端的存档?

二进制存档格式不可移植。因此,无论如何,请避免这种情况或使用试图便携的直接替代品:https://github.com/mika-fischer/eos-portable-archive

关于c++ - 我在使用 boost::serialization 时遇到一个问题,我的代码在 linux 中运行良好,但在 windows 中遇到异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52378103/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com