Segmentation violation in nodeHandle.subscribe
This code had been working earlier for my roscpp package. I integrated more code to this and have added a few C libraries but this code is a direct copy from the previous version. It fails everytime in {nh.subscribe}. I am using Ubuntu Linux 11.10 with ROS electric. I do not wish to move to a newer version of ROS at this juncture of development. I am getting a segmentation violation in the following code:
ros::init(argc, argv, "irobot_stargazer");
ros::NodeHandle nh;
ros::Subscriber sub;
sub = nh.subscribe("/cu/stargazer_marker_cu", 1, get_stargazer_coord);
//sub2 = nh.subscribe("/destXYT", 10, get_destination);
if(!sub)
{// the subscribe did not work
printf("could not subscribe to stargazer\n");
exit(0);
}
the error shown in gdb says: 0x00123c3b in ?? () from /lib/ld-linux.so.2
Can someone please let me know if there is something I am missing or supposed to add.
Edit 1: I am putting the backtrace for the code: 0 0x00123c3b in ?? () from /lib/ld-linux.so.2
1 0x005573cf in XmlRpc::XmlRpcSocket::accept (fd=12) at /tmp/buildd/ros-electric-ros-comm-1.6.7/debian/ros-electric-ros-comm/opt/ros/electric/stacks/ros_comm/utilities/xmlrpcpp/src/XmlRpcSocket.cpp:165
2 0x00551719 in XmlRpc::XmlRpcServer::acceptConnection (this=0x80b1698) at /tmp/buildd/ros-electric-ros-comm-1.6.7/debian/ros-electric-ros-comm/opt/ros/electric/stacks/ros_comm/utilities/xmlrpcpp/src/XmlRpcServer.cpp:152
3 0x0055163f in XmlRpc::XmlRpcServer::handleEvent (this=0x80b1698) at /tmp/buildd/ros-electric-ros-comm-1.6.7/debian/ros-electric-ros-comm/opt/ros/electric/stacks/ros_comm/utilities/xmlrpcpp/src/XmlRpcServer.cpp:142
4 0x00551340 in XmlRpc::XmlRpcDispatch::work (this=0x80b16a4, timeout=0.10000000000000001) at /tmp/buildd/ros-electric-ros-comm-1.6.7/debian/ros-electric-ros-comm/opt/ros/electric/stacks/ros_comm/utilities/xmlrpcpp/src/XmlRpcDispatch.cpp:131
5 0x00552004 in XmlRpc::XmlRpcServer::work (this=0x80b1698, msTime=0.10000000000000001) at /tmp/buildd/ros-electric-ros-comm-1.6.7/debian/ros-electric-ros-comm/opt/ros/electric/stacks/ros_comm/utilities/xmlrpcpp/src/XmlRpcServer.cpp:132
6 0x001c6dbf in ros::XMLRPCManager::serverThreadFunc (this=0x80b1688) at /tmp/buildd/ros-electric-ros-comm-1.6.7/debian/ros-electric-ros-comm/opt/ros/electric/stacks/roscomm/clients/cpp/roscpp/src/libros/xmlrpcmanager.cpp:258
7 0x001c92bb in operator() (p=
8 operator()
9 operator() (this=0x80b45a4) at /usr/include/boost/bind/bind_template.hpp:20
10 boost::detail::threaddata<boost::bi::bindt<void, boost::mfi::mf0
11 0x0059c3cc in threadproxy () from /usr/lib/libboostthread.so.1.46.1
12 0x003b3d31 in start_thread () from /lib/i386-linux-gnu/libpthread.so.0
13 0x0049a0ce in clone () from /lib/i386-linux-gnu/libc.so.6
Backtrace stopped: Not enough registers or memory available to unwind further
Here are the things that I have tried till now: 1. Initially created libraries by use of makefiles and called those makefiles through cmake. This produced a executeable linked to these libraries. 2. Tried creating a monolithic executeable with all the objet files wrapped into one. The final executeable generated fails at the same location, just before calling nh.subscribe().
The prototype for the function is void getstargazercoord(const stargazer_cu::Pose2DTagged::ConstPtr& data);
Asked by swingingiant on 2012-12-13 19:56:20 UTC
Comments
Looks OK to me. Try to compile it as a single program without other libraries, then you know it is not this code which is the problem.
Asked by dornhege on 2012-12-13 22:14:52 UTC
And please provide a more complete backtrace and maybe the definition of get_stargazer_coord.
Asked by Lorenz on 2012-12-14 00:00:39 UTC
I have ported the code to fuerte too but the same problem is cropping up.
Asked by swingingiant on 2012-12-15 19:13:50 UTC
I tested extensively with lots of different approaches and have narrowed down to the problem coming from ros::spinOnce(). I am guessing the error occurs every time I create the nodehandle and add a subscriber there is a call to ros::spinOnce implicitly which creates the problem.
Asked by swingingiant on 2012-12-16 15:58:08 UTC
can anyone please provide a solution to this open problem as I am unable to make a headway in this. I hope the ROS team can provide some inputs on this problem.
Asked by swingingiant on 2013-01-15 00:50:50 UTC
Currently it is not possible to provide a solution because the problem cannot be reproduced. The code you posted should work in principle, but is incomplete. Please provide a minimal complete example given the missing definitions.
Asked by dornhege on 2013-01-15 01:51:59 UTC