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 926b673..70aeb2c 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 0eb29a3..53ab038 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 c6b1d48..02f308e 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);
+      }
     }
   }