From cc4f86b8d69a25fc99dbc5be771ffa485a1ac9d0 Mon Sep 17 00:00:00 2001 From: Axel Date: Wed, 19 Aug 2020 09:31:50 +0200 Subject: [PATCH] Fixed trigger box generation for traffic signs with road width equal to 0 --- .../Carla/Source/Carla/Traffic/StopSignComponent.cpp | 6 ++++++ .../Carla/Source/Carla/Traffic/TrafficLightComponent.cpp | 3 +++ .../Carla/Source/Carla/Traffic/YieldSignComponent.cpp | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Traffic/StopSignComponent.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Traffic/StopSignComponent.cpp index d11f49ba7..707c0c89e 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Traffic/StopSignComponent.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Traffic/StopSignComponent.cpp @@ -41,6 +41,9 @@ void UStopSignComponent::InitializeSign(const carla::road::Map &Map) // Get 90% of the half size of the width of the lane float BoxSize = static_cast( 0.9*Map.GetLaneWidth(signal_waypoint)*0.5); + // Prevent a situation where the road width is 0 + // This could happen in a lane that is just appearing + BoxSize = std::max(0.01f, BoxSize); // Get min and max double LaneLength = Map.GetLane(signal_waypoint).GetLength(); double LaneDistance = Map.GetLane(signal_waypoint).GetDistance(); @@ -103,6 +106,9 @@ void UStopSignComponent::InitializeSign(const carla::road::Map &Map) auto NextWaypoint = CurrentWaypoint; float BoxSize = static_cast( 0.9*Map.GetLaneWidth(NextWaypoint)*0.5); + // Prevent a situation where the road width is 0 + // This could happen in a lane that is just appearing + BoxSize = std::max(0.01f, BoxSize); float UEBoxSize = 100*BoxSize; GenerateCheckBox(Map.ComputeTransform(NextWaypoint), UEBoxSize); while (true) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Traffic/TrafficLightComponent.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Traffic/TrafficLightComponent.cpp index 44a75f6c0..4d1e05731 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Traffic/TrafficLightComponent.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Traffic/TrafficLightComponent.cpp @@ -43,6 +43,9 @@ void UTrafficLightComponent::InitializeSign(const carla::road::Map &Map) // Get 90% of the half size of the width of the lane float BoxSize = static_cast( 0.9f*Map.GetLaneWidth(signal_waypoint)*0.5); + // Prevent a situation where the road width is 0 + // This could happen in a lane that is just appearing + BoxSize = std::max(0.01f, BoxSize); // Get min and max double LaneLength = Map.GetLane(signal_waypoint).GetLength(); double LaneDistance = Map.GetLane(signal_waypoint).GetDistance(); diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Traffic/YieldSignComponent.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Traffic/YieldSignComponent.cpp index c6aa4313e..02f07b309 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Traffic/YieldSignComponent.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Traffic/YieldSignComponent.cpp @@ -41,6 +41,9 @@ void UYieldSignComponent::InitializeSign(const carla::road::Map &Map) // Get 90% of the half size of the width of the lane float BoxSize = static_cast( 0.9*Map.GetLaneWidth(signal_waypoint)/2.0); + // Prevent a situation where the road width is 0 + // This could happen in a lane that is just appearing + BoxSize = std::max(0.01f, BoxSize); // Get min and max double LaneLength = Map.GetLane(signal_waypoint).GetLength(); double LaneDistance = Map.GetLane(signal_waypoint).GetDistance(); @@ -104,6 +107,9 @@ void UYieldSignComponent::InitializeSign(const carla::road::Map &Map) auto NextWaypoint = CurrentWaypoint; float BoxSize = static_cast( 0.9*Map.GetLaneWidth(NextWaypoint)/2.0); + // Prevent a situation where the road width is 0 + // This could happen in a lane that is just appearing + BoxSize = std::max(0.01f, BoxSize); float UEBoxSize = 100*BoxSize; GenerateCheckBox(Map.ComputeTransform(NextWaypoint), UEBoxSize); while (true)