Segmentation fault in publishing array message
Hi
I'm trying to publish polygonal position as message. The publisher is make correct but "segmentation error" shows when I rosrun the publisher, saying "Segmentation fault (core dumped)".
int main(int argc,char** argv)
{
ros::init(argc, argv, "line_formation");
ros::NodeHandle na;
geometry_msgs::Polygon destination;
ros::Subscriber sub= na.subscribe<sensor_msgs::Joy>("/joy",1,joyCallback);
ros::Publisher pub= na.advertise<geometry_msgs::Polygon>("uav_positions",10);
ros::Rate loop_rate(2);
while (ros::ok)
{
central_x +=array[4];
central_y +=-array[3];
central_z +=array[1];
destination.points[0].x=central_x;
destination.points[0].y=central_y;
destination.points[0].z=central_z;
pub.publish(destination);
ros::spinOnce();
loop_rate.sleep();
}
}
As it shows, I use message "geometry_msgs/Polygon". It seems its caused by publishing array. If I publish single point message as "geometry_msgs/Point", it works. But I need to publish several points. So I have to publish array.
Any idea how to solve it or other ways to publish several points position?
Thanks Glen