typeid()或dynamic_cast()如何导致程序崩溃(使用FLANN库)?

时间:2018-12-24 00:35:01

标签: c++ point-cloud-library typeid flann

我正在使用FLANN中的KdTree算法。这是出错的代码:

template<typename T>
base_any_policy* get_policy()
{
    static typename choose_policy<T>::type policy;
    std::cout << "getting typeid..." << std::endl << typeid(policy).name() << "typeid() seemed ok" << std::endl;
    return &policy;
}

程序只是崩溃了。仅输出getting typeid...

那只是我用于调试目的的代码。我遇到的原始问题在this line (FLANN version 1.9.1)

崩溃

我正在使用PCL库(在macOS Mojave上)来处理一些点云,而点云又使用了FLANN。但是,每次创建kdtree并调用setInputCloud()时,程序都会崩溃。

要进行调试,我将源代码的this line修改为上面提供的代码段。

很难重现此问题,因为当我创建一个简单的测试程序时,它不会崩溃。崩溃仅发生在我的一个大型项目中。

PS。 --fno-rtti标志未设置,或者上面的代码无法编译。

回溯:

1   flann::anyimpl::base_any_policy * flann::anyimpl::get_policy<flann::anyimpl::empty_any>()                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                any.h                   148  0x104e7252b 
2   flann::any::any()                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        any.h                   172  0x104e724d9 
3   flann::any::any()                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        any.h                   173  0x104e724b5 
4   std::pair<std::string const, flann::any>::pair<std::string&&, 0ul>(std::piecewise_construct_t, std::tuple<std::string&&>&, std::tuple<>&, std::__tuple_indices<0ul>, std::__tuple_indices<>)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             tuple                   1365 0x104e71ebf 
5   std::pair<std::string const, flann::any>::pair<std::string&&, 0ul>(std::piecewise_construct_t, std::tuple<std::string&&>&, std::tuple<>&, std::__tuple_indices<0ul>, std::__tuple_indices<>)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             tuple                   1366 0x104e71dce 
6   std::pair<std::string const, flann::any>::pair<std::string&&>(std::piecewise_construct_t, std::tuple<std::string&&>, std::tuple<>)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       utility                 487  0x104e71da4 
7   void std::allocator<std::__tree_node<std::__value_type<std::basic_string<char, std::char_traits<char>, std::allocator<char>>, flann::any>, void *>>::construct<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char>> const, flann::any>, std::piecewise_construct_t const&, std::tuple<std::basic_string<char, std::char_traits<char>, std::allocator<char>>&&>, std::tuple<>>(std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char>> const, flann::any> *, std::piecewise_construct_t const&&&, std::tuple<std::basic_string<char, std::char_traits<char>, std::allocator<char>>&&>&&, std::tuple<>&&)                                                                                                                                                                                                               memory                  1805 0x104e71da4 
8   void std::allocator_traits<std::allocator<std::__tree_node<std::__value_type<std::basic_string<char, std::char_traits<char>, std::allocator<char>>, flann::any>, void *>>>::__construct<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char>> const, flann::any>, std::piecewise_construct_t const&, std::tuple<std::basic_string<char, std::char_traits<char>, std::allocator<char>>&&>, std::tuple<>>(std::integral_constant<bool, true>, std::allocator<std::__tree_node<std::__value_type<std::basic_string<char, std::char_traits<char>, std::allocator<char>>, flann::any>, void *>>&, std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char>> const, flann::any> *, std::piecewise_construct_t const&&&, std::tuple<std::basic_string<char, std::char_traits<char>, std::allocator<char>>&&>&&, std::tuple<>&&) memory                  1715 0x104e71d33 
9   void std::allocator_traits<std::allocator<std::__tree_node<std::__value_type<std::basic_string<char, std::char_traits<char>, std::allocator<char>>, flann::any>, void *>>>::construct<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char>> const, flann::any>, std::piecewise_construct_t const&, std::tuple<std::basic_string<char, std::char_traits<char>, std::allocator<char>>&&>, std::tuple<>>(std::allocator<std::__tree_node<std::__value_type<std::basic_string<char, std::char_traits<char>, std::allocator<char>>, flann::any>, void *>>&, std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char>> const, flann::any> *, std::piecewise_construct_t const&&&, std::tuple<std::basic_string<char, std::char_traits<char>, std::allocator<char>>&&>&&, std::tuple<>&&)                                       memory                  1561 0x104e71ccf 
10  std::unique_ptr<std::__tree_node<std::__value_type<std::string, flann::any>, void *>, std::__tree_node_destructor<std::allocator<std::__tree_node<std::__value_type<std::string, flann::any>, void *>>>> std::__tree<std::__value_type<std::string, flann::any>, std::__map_value_compare<std::string, std::__value_type<std::string, flann::any>, std::less<std::string>, true>, std::allocator<std::__value_type<std::string, flann::any>>>::__construct_node<std::piecewise_construct_t const&, std::tuple<std::string&&>, std::tuple<>>(std::piecewise_construct_t const&&&, std::tuple<std::string&&>&&, std::tuple<>&&)                                                                                                                                                                                                                                            __tree                  2192 0x104e71c6b 
11  std::pair<std::__tree_iterator<std::__value_type<std::string, flann::any>, std::__tree_node<std::__value_type<std::string, flann::any>, void *> *, long>, bool> std::__tree<std::__value_type<std::string, flann::any>, std::__map_value_compare<std::string, std::__value_type<std::string, flann::any>, std::less<std::string>, true>, std::allocator<std::__value_type<std::string, flann::any>>>::__emplace_unique_key_args<std::string, std::piecewise_construct_t const&, std::tuple<std::string&&>, std::tuple<>>(std::string const&, std::piecewise_construct_t const&&&, std::tuple<std::string&&>&&, std::tuple<>&&)                                                                                                                                                                                                                                           __tree                  2137 0x104e702b1 
12  std::map<std::string, flann::any>::operator[](std::string&&)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             map                     1329 0x104e700b2 
13  flann::KDTreeSingleIndexParams::KDTreeSingleIndexParams(int, bool)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       kdtree_single_index.h   55   0x104e6fcde 
14  flann::KDTreeSingleIndexParams::KDTreeSingleIndexParams(int, bool)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       kdtree_single_index.h   54   0x104e6ef8a 
15  pcl::KdTreeFLANN<pcl::PointXY, flann::L2_Simple<float>>::setInputCloud(boost::shared_ptr<pcl::PointCloud<pcl::PointXY> const> const&, boost::shared_ptr<std::vector<int> const> const&)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  kdtree_flann.hpp        126  0x104e6897e 
16  MergeMatcher::match(std::vector<std::shared_ptr<GeometryModel>>&, std::vector<std::shared_ptr<Tracklet>>&, double)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       merge_matcher.cc        102  0x104f4280f 
17  SingleModelTracker::compute()                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            single_model_tracker.cc 146  0x104ff9dc2 
18  TrackingCenter::tracking_callback(boost::shared_ptr<perception_msgs::seg2trackMsg_<std::allocator<void>> const> const&)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  tracking_center.cc      252  0x104db343d 
19  boost::_mfi::mf1<void, TrackingCenter, boost::shared_ptr<perception_msgs::seg2trackMsg_<std::allocator<void>> const> const&>::operator()(TrackingCenter *, boost::shared_ptr<perception_msgs::seg2trackMsg_<std::allocator<void>> const> const&) const                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   mem_fn_template.hpp     165  0x104df8c81 
20  void boost::_bi::list2<boost::_bi::value<TrackingCenter *>, boost::arg<1>>::operator()<boost::_mfi::mf1<void, TrackingCenter, boost::shared_ptr<perception_msgs::seg2trackMsg_<std::allocator<void>> const> const&>, boost::_bi::rrlist1<boost::shared_ptr<perception_msgs::seg2trackMsg_<std::allocator<void>> const> const&>>(boost::_bi::type<void>, boost::_mfi::mf1<void, TrackingCenter, boost::shared_ptr<perception_msgs::seg2trackMsg_<std::allocator<void>> const> const&>&, boost::_bi::rrlist1<boost::shared_ptr<perception_msgs::seg2trackMsg_<std::allocator<void>> const> const&>&, int)                                                                                                                                                                                                                                                                  bind.hpp                319  0x104df8bdb 
... <More> (the rest are irrelevant)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

1 个答案:

答案 0 :(得分:0)

这可能是FLANN库的错误,如github上的thisthis发行票据所指出。我可能遇到的是“魔术静力学”问题。

解决方案由前面的链接给出。