segfault when reading rosbag
Hi all, I'm trying to parse a rosbag file. According to the guide here, I wrote something like this:
rosbag::Bag bag;
std::vector<std::string> topics;
std::cout << "Opening " << filename_ << std::endl;
bag.open(filename_.c_str(), rosbag::bagmode::Read);
std::cout << "Mode: " << bag.getMode() << std::endl;
topics.push_back(std::string("/Imu"));
topics.push_back(std::string("/joint_states"));
rosbag::View view(bag, rosbag::TopicQuery(topics));
foreach(rosbag::MessageInstance const m, view) {
std::cout << "Found message of type " << m.getDataType() << std::endl;
if(m.getDataType().compare("sensor_msgs/Imu") == 0) {
sensor_msgs::ImuConstPtr s = m.instantiate<sensor_msgs::Imu>();
cout << "S = " << s << std::endl;
double ax = s->linear_acceleration.x;
}
The address printed by S is not NULL, but when I reach the last line to get the data, I get a SEGFAULT.