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>
// 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);
+ }
}
}
// 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);
+ }
}
}
// 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);
+ }
}
}