我目前正在开发谷歌探戈平板电脑的应用程序,所以我使用superbuild脚本为ARM构建了pcl (来自https://github.com/Sabotaz/pcl-superbuild-with-release/releases)。
我遇到了一个奇怪的崩溃:pcl函数之一pcl :: ProjectInliers产生了一个“致命的信号” 7(SIGBUS)»错误。
我没有完全理解这个错误,文档说“它可能在取消引用未对齐的指针时发生,例如在一个不能被4整除的地址处引用一个四字整数。”,所以我不这样做理解,看看我的代码,它是如何发生的。
此外,我的所有变量似乎都很好地对齐(我使用https://stackoverflow.com/a/1898156/5533171检查了它。)
Backtraces似乎涉及Eigen数据结构错位,所以我认为问题不在我的代码中,而是在第三方库上。
以下是我的代码的相关部分(基于http://www.pointclouds.org/documentation/tutorials/planar_segmentation.php):
template<typename T> void SegmentationEngine<T>::ransac_loop(typename pcl::PointCloud<T>::Ptr cloud_blob, std::vector<Datatype::RansacPlane<T>>& planes) {
LOGD("size : %d", cloud_blob->points.size ());
typename pcl::PointCloud<T>::Ptr cloud (new pcl::PointCloud<T>);
copyPointCloud(*cloud_blob, *cloud);
int i = 0;
while (i < FILTER_SEGMENTATION_MAX_PLANES_NUMBER) {
typename pcl::PointCloud<T>::Ptr points (new pcl::PointCloud<T>);
pcl::PointIndices::Ptr inliers (new pcl::PointIndices ());
pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients ());
LOGD("remaining : %d", cloud->points.size ());
LOGD("Filters::sac_segmentation");
if (!Filters::sac_segmentation<T>(cloud,inliers, coefficients)) break; // plus de plans
LOGD("found plane with %d pts", inliers->indices.size());
// it crash here :
Filters::project_inliers<T>(cloud, inliers, coefficients, points, false); // don't copy all (extract)
planes.push_back( Datatype::RansacPlane<T>{ coefficients, points } );
typename pcl::PointCloud<T>::Ptr remaining (new pcl::PointCloud<T>);
Filters::extract_indices<T>(cloud, inliers, remaining, true); // remaining
cloud.swap(remaining);
i++;
}
LOGD("n planes : %d", planes.size());
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<typename T> bool sac_segmentation(typename pcl::PointCloud<T>::Ptr input_cloud, pcl::PointIndices::Ptr inliers, pcl::ModelCoefficients::Ptr coefficients) {
// Create the segmentation object
pcl::SACSegmentation<T> seg;
// Optional
seg.setOptimizeCoefficients (FILTER_SAC_SEGMENTATION_OPTIMIZE_COEFFICIENTS);
// Mandatory
seg.setModelType (FILTER_SAC_SEGMENTATION_MODEL_TYPE);
seg.setMethodType (FILTER_SAC_SEGMENTATION_METHOD_TYPE);
seg.setDistanceThreshold (FILTER_SAC_SEGMENTATION_DISTANCE_THRESOLD);
seg.setMaxIterations (FILTER_SAC_SEGMENTATION_MAX_ITERATIONS);
seg.setInputCloud (input_cloud);
seg.segment (*inliers, *coefficients);
if (inliers->indices.size () == 0)
{
return false;
}
return true;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<typename T> void project_inliers(typename pcl::PointCloud<T>::Ptr input_cloud, pcl::PointIndices::Ptr inliers, pcl::ModelCoefficients::Ptr coefficients, typename pcl::PointCloud<T>::Ptr output_cloud, bool copyall) {
// Project the model inliers
typename pcl::ProjectInliers<T> proj;
proj.setModelType (FILTER_PROJECT_INLIERS_MODEL_TYPE);
if (inliers != NULL)
proj.setIndices (inliers);
proj.setInputCloud (input_cloud);
proj.setModelCoefficients (coefficients);
proj.setCopyAllData (copyall);
// it crash here :
proj.filter (*output_cloud);
}
以下是相应的日志:
D/fr.limsi.registration: size : 36
D/fr.limsi.registration: remaining : 36
D/fr.limsi.registration: Filters::sac_segmentation
D/fr.limsi.registration: found plane with 36 pts
A/libc: Fatal signal 7 (SIGBUS) at 0x4be4fa38 (code=1), thread 1052 (si.registration)
这是回溯:
backtrace:
#00 pc 0055d55e /data/app-lib/fr.limsi.registration-1/libintegration.so
(std::vector<pcl::PointXYZRGBNormal, Eigen::aligned_allocator_indirection<pcl::PointXYZRGBNormal>
>::_M_fill_insert(__gnu_cxx::__normal_iterator<pcl::PointXYZRGBNormal*,
std::vector<pcl::PointXYZRGBNormal, Eigen::aligned_allocator_indirection<pcl::PointXYZRGBNormal> >
>, unsigned int, pcl::PointXYZRGBNormal const&)+621)
#01 pc 0064d995 /data/app-lib/fr.limsi.registration-1/libintegration.so
(std::vector<pcl::PointXYZRGBNormal, Eigen::aligned_allocator<pcl::PointXYZRGBNormal>
>::resize(unsigned int)+116)
#02 pc 008cc23b /data/app-lib/fr.limsi.registration-1/libintegration.so
(pcl::SampleConsensusModelPlane<pcl::PointXYZRGBNormal>::projectPoints(std::vector<int,
std::allocator<int> > const&, Eigen::Matrix<float, -1, 1, 0, -1, 1> const&,
pcl::PointCloud<pcl::PointXYZRGBNormal>&, bool)+514)
#03 pc 0066b457 /data/app-lib/fr.limsi.registration-1/libintegration.so
(pcl::ProjectInliers<pcl::PointXYZRGBNormal>::applyFilter(pcl::PointCloud<pcl::PointXYZRGBNormal>&)+
82)
如果有人知道会发生什么,请告诉我:)
谢谢,
Sablier