HuaYuXiao / Fast-Planner

[RA-L 2019] A Robust and Efficient Trajectory Planner for Quadrotors
GNU General Public License v3.0
3 stars 0 forks source link

Segmentation fault (Address not mapped to object [0x1]) #55

Closed HuaYuXiao closed 4 months ago

HuaYuXiao commented 4 months ago
Stack trace (most recent call last):
#9    Object "[0xffffffffffffffff]", at 0xffffffffffffffff, in 
#8    Object "/home/hyx020222/planner_ws/devel/lib/fast_planner/fast_planner_node", at 0x556af593a84d, in _start
#7    Object "/lib/x86_64-linux-gnu/libc.so.6", at 0x7f1f5b47d082, in __libc_start_main
#6    Object "/home/hyx020222/planner_ws/devel/lib/fast_planner/fast_planner_node", at 0x556af593836b, in main
#5    Object "/home/hyx020222/planner_ws/devel/lib/fast_planner/fast_planner_node", at 0x556af5941d31, in fast_planner::KinoReplanFSM::init(ros::NodeHandle&)
#4    Object "/home/hyx020222/planner_ws/devel/lib/fast_planner/fast_planner_node", at 0x556af5955466, in fast_planner::FastPlannerManager::initPlanModules(ros::NodeHandle&)
#3    Object "/home/hyx020222/planner_ws/devel/lib/libplan_env.so", at 0x7f1f5c05eb07, in SDFMap::initMap(ros::NodeHandle&)
#2    Object "/opt/ros/noetic/lib/libroscpp.so", at 0x7f1f5bf592ce, in ros::NodeHandle::getParam(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) const
#1    Object "/opt/ros/noetic/lib/libroscpp.so", at 0x7f1f5bf0a8ba, in ros::param::getImpl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, bool)
#0    Object "/lib/x86_64-linux-gnu/libc.so.6", at 0x7f1f5b5e49bd, in 
Segmentation fault (Address not mapped to object [0x1])
Segmentation fault (core dumped)
HuaYuXiao commented 4 months ago

从你提供的堆栈跟踪信息来看,这是一个C++程序在运行时遇到了段错误(Segmentation fault)。段错误通常是由于程序试图访问它没有权限访问的内存区域引起的。这里是一些可能的原因和解决方法:

  1. 指针访问错误:如果程序试图解引用一个空指针或无效的内存地址,就会发生段错误。检查堆栈跟踪中的#9行,这里显示了一个地址0xffffffffffffffff,这通常是一个空指针。

  2. 数组越界:如果程序试图访问数组的越界元素,也会导致段错误。检查所有数组操作,确保索引在有效范围内。

  3. 内存分配错误:如果程序在分配内存时出现问题,比如使用new而没有足够的内存,也可能导致段错误。

  4. ROS节点初始化问题:堆栈跟踪显示错误发生在ROS节点的初始化过程中。检查fast_planner::KinoReplanFSM::initfast_planner::FastPlannerManager::initPlanModules函数,看看是否有不正确的初始化或配置。

  5. 参数获取问题:在#2#1行,错误发生在尝试获取ROS参数时。确保传递给ros::NodeHandle::getParam的参数名称是正确的,并且节点确实提供了这个参数。

  6. 依赖库问题:错误发生在/opt/ros/noetic/lib/libroscpp.so/lib/x86_64-linux-gnu/libc.so.6中,这可能表明存在与ROS或C标准库相关的兼容性或配置问题。

为了解决这个问题,你可以:

最后,确保你的开发环境和依赖项都是最新的,并且正确配置。

HuaYuXiao commented 4 months ago

In C++14, the difference between void initPlanModules(ros::NodeHandle &nh); and void initPlanModules(ros::NodeHandle& nh); is subtle and has to do with the way parameters are passed to functions.

  1. With a space before the ampersand (&):

    • void initPlanModules(ros::NodeHandle &nh);
    • This is the traditional way of declaring a reference parameter in C++ before C++11. The space before the & is not necessary, but it was commonly used to distinguish reference parameters from pointer parameters.
  2. Without a space before the ampersand (&):

    • void initPlanModules(ros::NodeHandle& nh);
    • This is the preferred syntax in modern C++ (from C++11 onwards). The space before the & is omitted, which is considered better style and is less error-prone. This change was made to align the reference syntax with the universal reference syntax introduced in C++11 for perfect forwarding.

In terms of functionality, both declarations are equivalent in C++14. They both indicate that the function initPlanModules takes a reference to a ros::NodeHandle object named nh. The reference means that the function will operate directly on the object passed to it, rather than on a copy.

The choice between these two styles is mostly a matter of coding style and consistency within a codebase. The second form (void initPlanModules(ros::NodeHandle& nh);) is generally recommended for new code as it is cleaner and aligns with the modern C++ style guides.