Memory exception thrown when initializing node with SharedPtr
Whenever I initialize a new node with rclcpp::Node::make_shared
, a memory exception occurred. It worked fine before and suddenly won't let me. I can successfully declare a shared pointer with std::string such as std::shared_ptr<std::string> sNode = std::make_shared<std::string>();
, just not with rclcpp::Node
. I am guessing it could be caused by terminating the process while spinning the executor with detached thread? If yes, how can I terminate the thread that block me from using this shared pointer. If not, what could potentially cause this problem and how to solve? Here is a very simple code from the tutorial that I have issue with:
rclcpp::init(0, nullptr);
rclcpp::NodeOptions node_options;
node_options.automatically_declare_parameters_from_overrides(true);
rclcpp::Node::SharedPtr node = rclcpp::Node::make_shared("run_moveit_cpp", "", node_options); //stuck here
rclcpp::shutdown();
Any help would be greatly appreciated!
Asked by HarryLi on 2023-06-28 19:03:54 UTC
Answers
In my case, it turns out, after forced terminate the program after calling std::thread([&executor]() { executor.spin(); }).detach();
, the thread is spinning in the background even after the computer is rebooted. I fixed my issue by calling executor.cancel()
to shut down all running spinning functions, so it won't block me from declaring another shared pointer.
Asked by HarryLi on 2023-06-29 10:33:08 UTC
Comments