diff --git a/nav2_costmap_2d/src/costmap_2d_ros.cpp b/nav2_costmap_2d/src/costmap_2d_ros.cpp index c9ca90ad07..50e74c511b 100644 --- a/nav2_costmap_2d/src/costmap_2d_ros.cpp +++ b/nav2_costmap_2d/src/costmap_2d_ros.cpp @@ -657,11 +657,27 @@ Costmap2DROS::dynamicParametersCallback(std::vector parameter } } else if (type == ParameterType::PARAMETER_INTEGER) { if (name == "width") { - resize_map = true; - map_width_meters_ = parameter.as_int(); + if (parameter.as_int() > 0) { + resize_map = true; + map_width_meters_ = parameter.as_int(); + } else { + RCLCPP_ERROR( + get_logger(), "You try to set width of map to be negative or zero," + " this isn't allowed, please give a positive value."); + result.successful = false; + return result; + } } else if (name == "height") { - resize_map = true; - map_height_meters_ = parameter.as_int(); + if (parameter.as_int() > 0) { + resize_map = true; + map_height_meters_ = parameter.as_int(); + } else { + RCLCPP_ERROR( + get_logger(), "You try to set height of map to be negative or zero," + " this isn't allowed, please give a positive value."); + result.successful = false; + return result; + } } } else if (type == ParameterType::PARAMETER_STRING) { if (name == "footprint") {