From d532acd2c92226512b34cbc282f1bcedfd14fd2a Mon Sep 17 00:00:00 2001
From: Xiao Pan <xiao.pan@ansys.com>
Date: Mon, 16 May 2022 12:03:37 +0200
Subject: [PATCH] Adapt target lane-id type in the performance lane change
 control strategy

---
 src/Storyboard/Actions/LaneChangeAction.cpp | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/Storyboard/Actions/LaneChangeAction.cpp b/src/Storyboard/Actions/LaneChangeAction.cpp
index 8b8cdf4..b1c0aae 100644
--- a/src/Storyboard/Actions/LaneChangeAction.cpp
+++ b/src/Storyboard/Actions/LaneChangeAction.cpp
@@ -73,7 +73,7 @@ void LaneChangeAction::SetupControlStrategy()
 
     if (const auto absolute_target_lane = lane_change_target->GetAbsoluteTargetLane())
     {
-        control_strategy_->target_lane_id = std::stoul(absolute_target_lane->GetValue());
+        control_strategy_->target_lane_id = std::stol(absolute_target_lane->GetValue());
     }
     else if (const auto relative_target_lane = lane_change_target->GetRelativeTargetLane())
     {
@@ -87,16 +87,22 @@ void LaneChangeAction::SetupControlStrategy()
 
         const auto relative_pose = mantle_api::Pose{relative_entity.value().get().GetPosition(),
                                                     relative_entity.value().get().GetOrientation()};
-        if (const auto target_lane_id =
-                environment_->GetQueryService().GetRelativeLaneId(relative_pose, relative_target_lane->GetValue()))
-        {
-            control_strategy_->target_lane_id = target_lane_id.value();
-        }
-        else
+        const auto target_lane_id =
+            environment_->GetQueryService().GetRelativeLaneId(relative_pose, relative_target_lane->GetValue());
+
+        if (!target_lane_id.has_value())
         {
             throw std::runtime_error("LaneChangeAction: Cannot find the target lane to the reference entity \"" +
                                      relative_entity_name + "\". Please adjust the scenario.");
         }
+
+        if (target_lane_id.value() > static_cast<mantle_api::UniqueId>(std::numeric_limits<std::int64_t>::max()))
+        {
+            throw std::runtime_error("LaneChangeAction: Integer overflow detected in converting the target lane id \"" +
+                                     std::to_string(target_lane_id.value()) + "\".");
+        }
+
+        control_strategy_->target_lane_id = static_cast<int>(target_lane_id.value());
     }
     else
     {
-- 
GitLab