Fix crash issue when navi-mesh seperated 49/298049/1
authorEunki Hong <eunkiki.hong@samsung.com>
Wed, 30 Aug 2023 18:35:41 +0000 (03:35 +0900)
committerEunki Hong <eunkiki.hong@samsung.com>
Wed, 30 Aug 2023 18:35:41 +0000 (03:35 +0900)
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 <eunkiki.hong@samsung.com>
dali-scene3d/internal/algorithm/path-finder-djikstra.cpp
dali-scene3d/internal/algorithm/path-finder-spfa-double-way.cpp
dali-scene3d/internal/algorithm/path-finder-spfa.cpp

index 926b6730f82e572dd2122bd364e5d4925ea5e0f4..70aeb2c2206a8c99770bba84f8ee1af3111c397c 100644 (file)
@@ -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<WayPointData&>(waypoints[0]);
-      auto& wpTo   = static_cast<WayPointData&>(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<WayPointData&>(waypoints[0]);
+        auto& wpTo   = static_cast<WayPointData&>(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);
+      }
     }
   }
 
index 0eb29a3a3271ff57e32f6ef9cf5e3f1dbd3fbfae..53ab0380d749c31cceda6d7a6502345ac4655793 100644 (file)
@@ -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<WayPointData&>(waypoints[0]);
-      auto& wpTo   = static_cast<WayPointData&>(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<WayPointData&>(waypoints[0]);
+        auto& wpTo   = static_cast<WayPointData&>(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);
+      }
     }
   }
 
index c6b1d4872709308487671ffe1c42fdf95e2261b8..02f308e6788883f12f6e2a3211b6829f0049f19f 100644 (file)
@@ -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<WayPointData&>(waypoints[0]);
-      auto& wpTo   = static_cast<WayPointData&>(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<WayPointData&>(waypoints[0]);
+        auto& wpTo   = static_cast<WayPointData&>(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);
+      }
     }
   }