ros_comm icon indicating copy to clipboard operation
ros_comm copied to clipboard

roscpp: global variable name 'shutdown' will crash the ros node.

Open qpc001 opened this issue 2 years ago • 0 comments

When I setting a global variable bool shutdown = false; in main.cpp, and I setup a publisher to send something at /topic_xxx.

Version: ros-melodic

Env: Ubuntu18.04

Reproduction steps:

  1. rostopic echo /topic_xxx
  2. ctrl+c to closed rostopic echo
  3. the ros node which publishing /topic_xxx will crash.

code is here:

#include <ros/ros.h>
#include <sensor_msgs/PointCloud2.h>

bool shutdown = false;
int main(int argc, char **argv) {
    ros::init(argc, argv, "test");
    ros::NodeHandle nh;

    ros::Publisher pub_raw_map =
            nh.advertise<sensor_msgs::PointCloud2>("pointcloud_map", 1, true);
    ros::Publisher pub_probabilistic_map =
            nh.advertise<sensor_msgs::PointCloud2>("probabilistic_map", 1, true);

    sensor_msgs::PointCloud2 msg;
    pub_probabilistic_map.publish(msg);

    ros::spin();

    std::cout << "Quit..." << std::endl;
    return 0;
}

gdb log is: image

qpc001 avatar Aug 04 '23 17:08 qpc001