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

Revision history [back]

click to hide/show revision 1
initial version

You need to pre-allocate the points array before you assign members into it, or use a function that does the appropriate bounds-checking and resize for you. In particular, arrays in ROS messages in C++ are implemented as std::vectors, and std::vector::operator[] doesn't do any bounds checking.

If you just want to append items to your array, try:

geometry_msgs::Point32 tl;
polyStamp.polygon.points.push_back(tl);

If you already know how big your array is going to be, and you want to assign to specific indicies, try:

geometry_msgs::Point32 tl;
polyStamp.polygon.points.reserve(10); // ensure that there will be space for at least 10 points
polyStamp.polygon.points[0]=tl;