ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Segmentation Fault at ros::NodeHandle nh("node_name") [closed]

asked 2022-11-30 05:30:14 -0500

shouvik1984 gravatar image

updated 2022-11-30 05:30:44 -0500

Hello there,

I am facing a weird issue of getting a segmentation fault right in the second line of main function. Immediately after

ros::init(argc,argv,"node_name");
ros::NodeHandle nh("node_name");

Getting segmentation at NodeHandle function. The following is the back trace of the callstack where exception has occured.

Thread 1 "removed" received signal SIGSEGV, Segmentation fault.
0x00007ffff750ec15 in ros::names::validate(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> >&) () from /opt/ros/noetic/lib/libroscpp.so
(gdb) bt
#0  0x00007ffff750ec15 in ros::names::validate(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> >&) () at /opt/ros/noetic/lib/libroscpp.so
#1  0x00007ffff753d8a2 in ros::NodeHandle::resolveName(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool) const () at /opt/ros/noetic/lib/libroscpp.so
#2  0x00007ffff753f5d5 in ros::NodeHandle::initRemappings(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<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&) () at /opt/ros/noetic/lib/libroscpp.so
#3  0x00007ffff7540a1e in ros::NodeHandle::NodeHandle(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<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&) ()
    at /opt/ros/noetic/lib/libroscpp.so
#4  0x00005555555e216d in main(int, char**) (argc=1, argv=0x7fffffffe1e8) at /removed/src/main.cpp:6

Please help in troubleshooting this issue.

Ros Version: ROS1 Noetic

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by shouvik1984
close date 2023-03-17 06:30:12.536421

2 Answers

Sort by ยป oldest newest most voted
0

answered 2022-12-02 07:57:51 -0500

shouvik1984 gravatar image

Looks like there is an issue with using

#pragma pack(1)

for one of the include files I was using for several structures in it. Once they were removed the sigsev is removed. However this needs further investigation on why is this happening

Regards Shouvik

edit flag offensive delete link more

Comments

A likely explanation would be you're changing the in-memory layout of structs. Since you are using a binary distribution of roscpp, which wasn't compiled with that particular setting for padding/packing, you've introduced an ABI incompatibility. SEGFAULTs are one of the many things which can then happen.

If you need to override padding/packing settings for specific structs, limit the setting to just those data types. Do not set it globally, especially not before you #include other headers.

gvdhoorn gravatar image gvdhoorn  ( 2022-12-03 06:49:06 -0500 )edit
0

answered 2022-12-01 06:46:01 -0500

Mike Scheutzow gravatar image

updated 2022-12-01 06:46:29 -0500

The typical way to create a NodeHandle object is:

ros::NodeHandle nh;

What are you trying to do by passing an argument to the constructor?

edit flag offensive delete link more

Comments

The argument creates the node namespace. The rostopic will appear as /<node_name>/topic name as opposed to /topic_name

I have tried

ros::NodeHandle nh;
ros::NodeHandle nh("~");
ros::NodeHandle nh("<node_name>");

In all three cases I am facing the same issue.

Regards Shouvik

shouvik1984 gravatar image shouvik1984  ( 2022-12-02 05:59:53 -0500 )edit

I find it difficult to believe you are getting a ros::names::validate() error from a node named "node_name". If the string is actually something else, please share it. Also tell us the exact command line you are using to run this node.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2022-12-02 06:20:19 -0500 )edit

Even without any argument I am getting ros::names::validate() exception

ros::NodeHandle nh;

Regards Shouvik Das

shouvik1984 gravatar image shouvik1984  ( 2022-12-02 07:34:20 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2022-11-30 05:30:14 -0500

Seen: 129 times

Last updated: Dec 01 '22