0
$\begingroup$

Rosanswers logo

Hello all, I am attempting the following:

class Durp
{
  tf::TransformListener _tfListener;
  tf::StampedTransform * saveMyTransform;

  Durp() : saveMyTransform(NULL)
  {
    Nodehandle n;
    someSub = n.sub(bla bla bla &callback);
  }

  ~Durp()
  {
    if(saveMyTransform!=NULL) delete saveMyTransform
  }

  void callback(geo_msgs::StampedPoint incPoint)
  {
     tf::StampedTransform tempTransform; //

Could someone please shed some light on what I am doing wrong. I would sincerely appreciate, I am ripping my hair out.


Segfault for StampedTransform tempTransform dump:

0x00007fffeba92116 in std::basic_string, std::allocator >::~basic_string() () from /usr/lib/libstdc++.so.6
(gdb) bt
#0  0x00007fffeba92116 in std::basic_string, std::allocator >::~basic_string() () from /usr/lib/libstdc++.so.6
#1  0x000000000041d321 in ~StampedTransform (this=0x7fffd4f7b2b0, __in_chrg=) at /opt/ros/electric/stacks/geometry/tf/include/tf/transform_datatypes.h:89
#2  0x00007fffee75421a in tf::Transformer::setTransform (this=, transform=, authority=)
    at /tmp/buildd/ros-electric-geometry-1.6.1/debian/ros-electric-geometry/opt/ros/electric/stacks/geometry/tf/src/tf.cpp:438
#3  0x00007fffee7670a5 in tf::TransformListener::subscription_callback (this=, msg=)
    at /tmp/buildd/ros-electric-geometry-1.6.1/debian/ros-electric-geometry/opt/ros/electric/stacks/geometry/tf/src/transform_listener.cpp:326
#4  0x00007fffee76d1ab in boost::function1 > const> const&>::operator() (function_obj_ptr=, a0=DWARF-2 expression error: DW_OP_reg operations must be used either alone or in conjuction with DW_OP_piece.
)
    at /usr/include/boost/function/function_template.hpp:1013
#5  boost::detail::function::void_function_obj_invoker1 > const> const&)>, void, boost::shared_ptr > const> >::invoke(boost::detail::function::function_buffer&, boost::shared_ptr > const>) (function_obj_ptr=, a0=DWARF-2 expression error: DW_OP_reg operations must be used either alone or in conjuction with DW_OP_piece.
)
    at /usr/include/boost/function/function_template.hpp:153
#6  0x00007fffee770890 in boost::function1 > const> >::operator() (this=0x7fffd0000a70, params=)
    at /usr/include/boost/function/function_template.hpp:1013
#7  ros::SubscriptionCallbackHelperT > const> const&, void>::call (this=0x7fffd0000a70, params=)
    at /opt/ros/electric/stacks/ros_comm/clients/cpp/roscpp/include/ros/subscription_callback_helper.h:180

Backtrace of when I pass my dynamically allocated Transform in

0 0x00007fffeba921fd in std::string::assign(std::string const&) () from /usr/lib/libstdc++.so.6 #1 0x00007fffee75581e in std::string::operator= (this=, target_frame=, source_frame=, time=..., transform=...) at /usr/include/c++/4.4/bits/basic_string.h:506 #2 tf::Transformer::lookupTransform (this=, target_frame=, source_frame=, time=..., transform=...) at /tmp/buildd/ros-electric-geometry-1.6.1/debian/ros-electric-geometry/opt/ros/electric/stacks/geometry/tf/src/tf.cpp:483 #3 0x0000000000439494 in RaveServer::displayWaypoint (this=0x7fffffffd9c0, incomingWaypoint=DWARF-2 expression error: DW_OP_reg operations must be used either alone or in conjuction with DW_OP_piece. ) at /home/constantin/workspace/rospackages/OpenRAVEROSInterp/src/RaveServer.cpp:230 #4 0x0000000000426783 in boost::_mfi::mf1 > >::operator() (function_obj_ptr=..., a0=DWARF-2 expression error: DW_OP_reg operations must be used either alone or in conjuction with DW_OP_piece. ) at /usr/include/boost/bind/mem_fn_template.hpp:162 #5 operator() > >, boost::_bi::list1 >&> > ( function_obj_ptr=..., a0=DWARF-2 expression error: DW_OP_reg operations must be used either alone or in conjuction with DW_OP_piece. ) at /usr/include/boost/bind/bind.hpp:306 #6 operator() > > (function_obj_ptr=..., a0=DWARF-2 expression error: DW_OP_reg operations must be used either alone or in conjuction with DW_OP_piece. ) at /usr/include/boost/bind/bind_template.hpp:32 #7 boost::detail::function::void_function_obj_invoker1 > >, boost::_bi::list2, boost::arg > >, void, geometry_msgs::PointStamped_ > >::invoke (function_obj_ptr=..., a0=DWARF-2 expression error: DW_OP_reg operations must be used either alone or in conjuction with DW_OP_piece. ) at /usr/include/boost/function/function_template.hpp:153 #8 0x000000000042bb92 in boost::function1 > >::operator() (this=0x7fffd0016780, params=) at /usr/include/boost/function/function_template.hpp:1013 #9 ros::SubscriptionCallbackHelperT >, void>::call (this=0x7fffd0016780, params=) at /opt/ros/electric/stacks/ros_comm/clients/cpp/roscpp/include/ros/subscription_callback_helper.h:180

Originally posted by Constantin S on ROS Answers with karma: 296 on 2011-11-11

Post score: 0


Original comments

Comment by tfoote on 2011-11-14:
The best thing to do is make a small test program which reproduces the problem. Often this will help you to find the problem without even needing external help. And it makes it possible to isolate the problem.

Comment by Constantin S on 2011-11-12:
be helpful? Thank you Ivan.

Comment by Constantin S on 2011-11-12:
Hi Ivan, the code is large and is a module for OpenRAVE. What part of the code would you be interested in? The callback is where the code always segfaults. If I use tempTransform, I segfault in the default constructor. If I comment it out, I segFault in the lookUpTransform. would the code stil

Comment by Ivan Dryanovski on 2011-11-11:
Could you post the full code? It might be more helpful.

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

Your backtrace shows that the segfault occurs in STL code, namely the basic_string allocator. It looks like some other code of yours has corrupted the heap memory management. That's a nasty bug because the corruption might have happened some time before, possibly even in a totally unrelated part of your program. Maybe you have overrun the bounds of an array/vector, or written to an uninitialized pointer that happens to refer to valid (but otherwise used) memory?

I'd try to comment out parts until the segfault disappears, then try to locate the culprit in that code part.


Originally posted by roehling with karma: 1951 on 2011-11-13

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by Constantin S on 2011-11-16:
debug flags. I am attaching the differing CMake's below... Could you guys please give me some more intuition on the problem? This is just nuts.

Comment by Constantin S on 2011-11-16:
identical classes. One worked one segfaulted. So I checked the CMakeLists, the one that worked was a basic CMakeList, the other was a custom I had built in case a person didn't have the openrave ros package. However, now I am thinking the only reason this is working is because it's build with

Comment by Constantin S on 2011-11-16:
Okay so I ... want to say I fixed it ... but I don't know. This has been a very very weird rabbit hole. I did exactly what you suggested but the opposite way, I started with a base class that worked and slowly started adding everything I needed. Low and behold, I eventually ended up with two

Comment by roehling on 2011-11-15:
I agree with Asomerville: Valgrind can help tremendously. You can install it with sudo apt-get install valgrind. The catch is that is slows down your program quite a lot and doubles your memory requirements. However, with a bit of luck Valgrind will tell you exactly where your bug is.

Comment by Constantin S on 2011-11-15:
Thanks guys, I will definitely take a look into this, it is a very valid possibility. When you say comment out parts, you mean everything but the StampedTransform? When I comment out the StampedTransform the segfault disappears.

Comment by Asomerville on 2011-11-14:
...and that using smart pointers (boost:: shared_ptr and auto_ptr) for all pointers will avoid a lot of headache.

Comment by Asomerville on 2011-11-14:
I'd also add that the use of valgrind memtool would likely quickly catch the culprit.

$\endgroup$
0
$\begingroup$

Rosanswers logo

Your problem could also be related to this question. If different versions of the same library are linked together (possibly because one of them has simply been source-copied into another one), and the linker does not catch this at link-time, runtime errors and segmentation faults can occur.

This is usually a problem with precompiled closed-source libraries. It's worth investigating though.


Originally posted by roehling with karma: 1951 on 2011-11-18

This answer was NOT ACCEPTED on the original site

Post score: 1


Original comments

Comment by Constantin S on 2011-11-18:
I'm starting to think this may have been the problem, valgrind did not show any memleaks in my code ... just a whole lot in QT code

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.