From 29a7ac7ee5ba961e9138ff0381a7812a23009c99 Mon Sep 17 00:00:00 2001 From: Norbert Prokopiuk Date: Mon, 26 Oct 2026 12:24:37 +0100 Subject: [PATCH] Added early return if no ros2 node Signed-off-by: Norbert Prokopiuk --- .../Clients/ROS2SimulationInterfacesSystemComponent.cpp | 6 ++++++ .../Clients/ROS2SimulationInterfacesSystemComponent.h | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/Gems/SimulationInterfaces/Code/Source/Clients/ROS2SimulationInterfacesSystemComponent.cpp b/Gems/SimulationInterfaces/Code/Source/Clients/ROS2SimulationInterfacesSystemComponent.cpp index 7643ff1557..ff52ab03d9 100644 --- a/Gems/SimulationInterfaces/Code/Source/Clients/ROS2SimulationInterfacesSystemComponent.cpp +++ b/Gems/SimulationInterfaces/Code/Source/Clients/ROS2SimulationInterfacesSystemComponent.cpp @@ -87,6 +87,12 @@ namespace ROS2SimulationInterfaces rclcpp::Node::SharedPtr ros2Node = rclcpp::Node::SharedPtr(ROS2::ROS2Interface::Get()->GetNode()); AZ_Assert(ros2Node, "ROS2 node is not available."); + if (!ros2Node) + { + AZ_Warning("ROS2SimulationInterfaces", false, "ROS 2 Node unavailable, ROS 2 handlers won't be created"); + return; + } + RegisterInterface(ros2Node); RegisterInterface(ros2Node); RegisterInterface(ros2Node); diff --git a/Gems/SimulationInterfaces/Code/Source/Clients/ROS2SimulationInterfacesSystemComponent.h b/Gems/SimulationInterfaces/Code/Source/Clients/ROS2SimulationInterfacesSystemComponent.h index 31c27aa639..1fd801643c 100644 --- a/Gems/SimulationInterfaces/Code/Source/Clients/ROS2SimulationInterfacesSystemComponent.h +++ b/Gems/SimulationInterfaces/Code/Source/Clients/ROS2SimulationInterfacesSystemComponent.h @@ -54,6 +54,12 @@ namespace ROS2SimulationInterfaces void RegisterInterface(rclcpp::Node::SharedPtr ros2Node) { AZStd::shared_ptr handler = AZStd::make_shared(); + if (!ros2Node) + { + AZ_Warning("ROS2SimulationInterfaces", false, "Failed to create handler %s, ROS 2 node not available", handler->GetTypeName().data()); + return; + } + handler->Initialize(ros2Node); if (handler->IsValid()) {