title: segmentation fault (core dumped) ROS c++ arrow
body: <p>I'm trying to read a geometry_msgs::PoseArray and convert it to a geometry_msgs::Pose in c++ for ROS. It should only convert the data when there is data on topic /tag_detections_pose. When I run this node( see code), I get a segmentation fault (core dumped) at the marked location when there is an empty array on /tag_detections_pose. I expect this to be an issue with pointers, but cannot find where exactly. I think I have to initialize my pointer, but I don't see where exactly.
  (b.t.w. The code is to convert apriltag_ros messages to be readable by simulink)</p>
  
  <pre><code>#include "ros/ros.h"
  #include &lt;geometry_msgs/Pose.h&gt;
  #include &lt;geometry_msgs/PoseArray.h&gt;
  #include &lt;std_msgs/Bool.h&gt;
  #include &lt;array&gt;
  
  
  class SubscribeAndPublish
  {
  public:
    SubscribeAndPublish()
    {
      //Topic you want to publish
      pub_ = n_.advertise&lt;geometry_msgs::Pose&gt;("/tag_pose", 1);
  
      //Topic you want to subscribe
      sub_ = n_.subscribe&lt;geometry_msgs::PoseArray&gt;("/tag_detections_pose", 1, &amp;SubscribeAndPublish::callback, this);
    }
  
    void callback(const geometry_msgs::PoseArray::ConstPtr&amp; input)
    {
      if (input) {
        geometry_msgs::Pose output;
  
        output.position.x = input-&gt;poses[0].position.x; //Here I get the segmentation fault
        output.position.y = input-&gt;poses[0].position.y;
        output.position.z = input-&gt;poses[0].position.z;
        output.orientation.x = input-&gt;poses[0].orientation.x;
        output.orientation.y = input-&gt;poses[0].orientation.y;
        output.orientation.z = input-&gt;poses[0].orientation.z;
        output.orientation.w = input-&gt;poses[0].orientation.w;
        pub_.publish(output);
      }
  
    }
  
  private:
    ros::NodeHandle n_;
    ros::Publisher pub_;
    ros::Subscriber sub_;
  
  };//End of class SubscribeAndPublish
  
  int main(int argc, char **argv)
  {
    //Initiate ROS
    ros::init(argc, argv, "apriltag_to_simu_V2");
  
    SubscribeAndPublish SAPObject;
  
    ros::spin();
  
    return 0;
  }
  </code></pre>
  
  <p>EDIT: some extra information.
  Whenever I read the next data from /tag_detections_pose, the segmentation fault occurs.</p>
  
  <pre><code>header: 
    seq: 14192
    stamp: 
      secs: 1519941974
      nsecs: 650975624
    frame_id: usb_cam
  poses: []
  ---
  header: 
    seq: 14193
    stamp: 
      secs: 1519941974
      nsecs: 995796728
    frame_id: usb_cam
  poses: []
  ---
  </code></pre>
  
  <p>Whenever I see an apriltag, there is no segmentation fault. Then the following code comes from /tag_detections_pose:</p>
  
  <pre><code>---
  header: 
    seq: 80
    stamp: 
      secs: 1519981664
      nsecs: 100302767
    frame_id: usb_cam
  poses: 
    - 
      position: 
        x: 0.110443956833
        y: -0.080843233518
        z: 0.753152633488
      orientation: 
        x: 0.706039345202
        y: 0.705726892216
        z: -0.0580458686961
        w: 0.00941667438916
  ---
  header: 
    seq: 81
    stamp: 
      secs: 1519981664
      nsecs: 368606478
    frame_id: usb_cam
  poses: 
    - 
      position: 
        x: 0.110435802307
        y: -0.0808251086937
        z: 0.753089835655
      orientation: 
        x: 0.706068882885
        y: 0.705719138117
        z: -0.0577643573596
        w: 0.0095136604333
  ---
  </code></pre>