diff --git a/source/modulo_components/include/modulo_components/Component.hpp b/source/modulo_components/include/modulo_components/Component.hpp index 440b2341..429dbcb0 100644 --- a/source/modulo_components/include/modulo_components/Component.hpp +++ b/source/modulo_components/include/modulo_components/Component.hpp @@ -32,9 +32,9 @@ class Component : public rclcpp::Node, public ComponentInterface { explicit Component(const rclcpp::NodeOptions& node_options, const std::string& fallback_name = "Component"); /** - * @brief Virtual default destructor. + * @brief Destructor that joins the thread if necessary. */ - virtual ~Component() = default; + virtual ~Component(); protected: /** diff --git a/source/modulo_components/src/Component.cpp b/source/modulo_components/src/Component.cpp index cb0ab8af..59f300c0 100644 --- a/source/modulo_components/src/Component.cpp +++ b/source/modulo_components/src/Component.cpp @@ -18,6 +18,12 @@ Component::Component(const NodeOptions& node_options, const std::string& fallbac this->add_predicate("in_error_state", false); } +Component::~Component() { + if (this->execute_thread_.joinable()) { + this->execute_thread_.join(); + } +} + void Component::step() { try { this->evaluate_periodic_callbacks();