diff --git a/src/dijkstrasearch.c b/src/dijkstrasearch.c index 39e9a68..fa682c4 100644 --- a/src/dijkstrasearch.c +++ b/src/dijkstrasearch.c @@ -254,6 +254,14 @@ int dijkstra_search_route_to_geojson(struct dijkstra_search *search, if (node_last) { path_to_this = search->states[node_last->uid]->cheapest_path; path_to_next = search->states[node->uid]->cheapest_path; + if (!path_to_next) { + report(LL_CRITICAL, "INTERNAL ERROR: path_to_next is NULL"); + break; + } + if (!path_to_this) { + // This happens at the very beginning. + path_to_this = path_to_next; // Pretend we were already where we started. + } heading = atan2f((node->position.y - node_last->position.y), (node->position.x - node_last->position.x)) / (M_PI * 2) * 360; if (heading < 0.0)