From e6e918ad821ee596e9229014faa40835d0311925 Mon Sep 17 00:00:00 2001 From: Eunki Hong Date: Thu, 31 Aug 2023 03:35:41 +0900 Subject: [PATCH] Fix crash issue when navi-mesh seperated It is possible that there is no path between navi-mesh polygons. If then, we return empty WayPointList. And then, crashed. To avoid that cases, let we check whether FindPath result empty. Change-Id: Id506c50022678c442d609d219d8c9baf53b46408 Signed-off-by: Eunki Hong --- .../internal/algorithm/path-finder-djikstra.cpp | 26 ++++++++++++---------- .../algorithm/path-finder-spfa-double-way.cpp | 26 ++++++++++++---------- .../internal/algorithm/path-finder-spfa.cpp | 26 ++++++++++++---------- 3 files changed, 42 insertions(+), 36 deletions(-) diff --git a/dali-scene3d/internal/algorithm/path-finder-djikstra.cpp b/dali-scene3d/internal/algorithm/path-finder-djikstra.cpp index 926b673..70aeb2c 100644 --- a/dali-scene3d/internal/algorithm/path-finder-djikstra.cpp +++ b/dali-scene3d/internal/algorithm/path-finder-djikstra.cpp @@ -79,18 +79,20 @@ Scene3D::Algorithm::WayPointList PathFinderAlgorithmDjikstra::FindPath(const Dal // Get waypoints waypoints = FindPath(polyIndexFrom, polyIndexTo); - // replace first and last waypoint - auto& wpFrom = static_cast(waypoints[0]); - auto& wpTo = static_cast(waypoints.back()); - - Vector2 fromCenter(wpFrom.point3d.x, wpFrom.point3d.y); - wpFrom.point3d = outPosFrom; - wpFrom.point2d = fromCenter - Vector2(outPosFrom.x, outPosFrom.y); - - Vector2 toCenter(wpTo.point3d.x, wpTo.point3d.y); - wpTo.point3d = outPosTo; - wpTo.point2d = toCenter - Vector2(outPosTo.x, outPosTo.y); - wpTo.point3d = outPosTo; + if(!waypoints.empty()) + { + // replace first and last waypoint + auto& wpFrom = static_cast(waypoints[0]); + auto& wpTo = static_cast(waypoints.back()); + + Vector2 fromCenter(wpFrom.point3d.x, wpFrom.point3d.y); + wpFrom.point3d = outPosFrom; + wpFrom.point2d = fromCenter - Vector2(outPosFrom.x, outPosFrom.y); + + Vector2 toCenter(wpTo.point3d.x, wpTo.point3d.y); + wpTo.point3d = outPosTo; + wpTo.point2d = toCenter - Vector2(outPosTo.x, outPosTo.y); + } } } diff --git a/dali-scene3d/internal/algorithm/path-finder-spfa-double-way.cpp b/dali-scene3d/internal/algorithm/path-finder-spfa-double-way.cpp index 0eb29a3..53ab038 100644 --- a/dali-scene3d/internal/algorithm/path-finder-spfa-double-way.cpp +++ b/dali-scene3d/internal/algorithm/path-finder-spfa-double-way.cpp @@ -118,18 +118,20 @@ Scene3D::Algorithm::WayPointList PathFinderAlgorithmSPFADoubleWay::FindPath(cons // Get waypoints waypoints = FindPath(polyIndexFrom, polyIndexTo); - // replace first and last waypoint - auto& wpFrom = static_cast(waypoints[0]); - auto& wpTo = static_cast(waypoints.back()); - - Vector2 fromCenter(wpFrom.point3d.x, wpFrom.point3d.y); - wpFrom.point3d = outPosFrom; - wpFrom.point2d = fromCenter - Vector2(outPosFrom.x, outPosFrom.y); - - Vector2 toCenter(wpTo.point3d.x, wpTo.point3d.y); - wpTo.point3d = outPosTo; - wpTo.point2d = toCenter - Vector2(outPosTo.x, outPosTo.y); - wpTo.point3d = outPosTo; + if(!waypoints.empty()) + { + // replace first and last waypoint + auto& wpFrom = static_cast(waypoints[0]); + auto& wpTo = static_cast(waypoints.back()); + + Vector2 fromCenter(wpFrom.point3d.x, wpFrom.point3d.y); + wpFrom.point3d = outPosFrom; + wpFrom.point2d = fromCenter - Vector2(outPosFrom.x, outPosFrom.y); + + Vector2 toCenter(wpTo.point3d.x, wpTo.point3d.y); + wpTo.point3d = outPosTo; + wpTo.point2d = toCenter - Vector2(outPosTo.x, outPosTo.y); + } } } diff --git a/dali-scene3d/internal/algorithm/path-finder-spfa.cpp b/dali-scene3d/internal/algorithm/path-finder-spfa.cpp index c6b1d48..02f308e 100644 --- a/dali-scene3d/internal/algorithm/path-finder-spfa.cpp +++ b/dali-scene3d/internal/algorithm/path-finder-spfa.cpp @@ -56,18 +56,20 @@ Scene3D::Algorithm::WayPointList PathFinderAlgorithmSPFA::FindPath(const Dali::V // Get waypoints waypoints = FindPath(polyIndexFrom, polyIndexTo); - // replace first and last waypoint - auto& wpFrom = static_cast(waypoints[0]); - auto& wpTo = static_cast(waypoints.back()); - - Vector2 fromCenter(wpFrom.point3d.x, wpFrom.point3d.y); - wpFrom.point3d = outPosFrom; - wpFrom.point2d = fromCenter - Vector2(outPosFrom.x, outPosFrom.y); - - Vector2 toCenter(wpTo.point3d.x, wpTo.point3d.y); - wpTo.point3d = outPosTo; - wpTo.point2d = toCenter - Vector2(outPosTo.x, outPosTo.y); - wpTo.point3d = outPosTo; + if(!waypoints.empty()) + { + // replace first and last waypoint + auto& wpFrom = static_cast(waypoints[0]); + auto& wpTo = static_cast(waypoints.back()); + + Vector2 fromCenter(wpFrom.point3d.x, wpFrom.point3d.y); + wpFrom.point3d = outPosFrom; + wpFrom.point2d = fromCenter - Vector2(outPosFrom.x, outPosFrom.y); + + Vector2 toCenter(wpTo.point3d.x, wpTo.point3d.y); + wpTo.point3d = outPosTo; + wpTo.point2d = toCenter - Vector2(outPosTo.x, outPosTo.y); + } } } -- 2.7.4