From 279e4b752330581c2118bdf34194d28af488bec2 Mon Sep 17 00:00:00 2001 From: jazzza Date: Thu, 8 May 2014 13:12:59 +1200 Subject: [PATCH] Fix for null pointer exception Under certain conditions or if all paths are exausted sortedOpenNodes.poll(); will return null. --- .../util/algorithm/path/astar/AStarPathFinder.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/org/andengine/util/algorithm/path/astar/AStarPathFinder.java b/src/org/andengine/util/algorithm/path/astar/AStarPathFinder.java index 13be0af1e..4d68e9704 100644 --- a/src/org/andengine/util/algorithm/path/astar/AStarPathFinder.java +++ b/src/org/andengine/util/algorithm/path/astar/AStarPathFinder.java @@ -77,6 +77,10 @@ public Path findPath(final IPathFinderMap pPathFinderMap, final int pXMin, fi while (openNodes.size() > 0) { /* The first Node in the open list is the one with the lowest cost. */ currentNode = sortedOpenNodes.poll(); + if (currentNode == null) { + break; + } + final long currentNodeID = currentNode.mID; if (currentNodeID == toNodeID) { break; @@ -151,7 +155,7 @@ public Path findPath(final IPathFinderMap pPathFinderMap, final int pXMin, fi sortedOpenNodes.clear(); /* Check if a path was found. */ - if (currentNode.mID != toNodeID) { + if (currentNode == null || currentNode.mID != toNodeID) { return null; } @@ -275,4 +279,4 @@ public boolean equals(final Node pNode) { // Inner and Anonymous Classes // =========================================================== } -} \ No newline at end of file +}