Game logic crashes on Android only

I’m developing a game for iOS/Android. I’m primarily working in Xcode, so I’m testing the code on iPhone regularly and the on Android not so often. Everything’s been going great so far, until today, I have a strange crash on Android only that appears to be from my game logic. The particular function it crashes on uses the A* path-finding algorithm to find the shortest route between two points, here’s the some console logs from the iPhone version:

cocos2d: hexagon index 12 //this is the start position cocos2d: hexagon index 36 //this is the end position cocos2d: num walkable steps returned by hexagon at index 12 is 4 //finds the shortest route to the end potion cocos2d: num walkable steps returned by hexagon at index 21 is 5 cocos2d: num walkable steps returned by hexagon at index 11 is 4 cocos2d: num walkable steps returned by hexagon at index 29 is 6 cocos2d: num walkable steps returned by hexagon at index 20 is 5 cocos2d: num walkable steps returned by hexagon at index 10 is 5 cocos2d: num walkable steps returned by hexagon at index 38 is 6 cocos2d: num walkable steps returned by hexagon at index 28 is 5 cocos2d: num walkable steps returned by hexagon at index 37 is 5 cocos2d: num walkable steps returned by hexagon at index 27 is 4 cocos2d: target found!!!!! cocos2d: step index = 36 //printing the route back to the start position cocos2d: step index = 37 cocos2d: step index = 38 cocos2d: step index = 29 cocos2d: step index = 21 cocos2d: step index = 12 cocos2d: go taken //success!

That was a successful run on the iPhone simulator, where I’ve tested the code numerous times and it seems robust. Here’s a run from the android simulator:

10-28 14:53:49.481: D/cocos2d-x debug info(847): hexagon index 25 //this is the start position 10-28 14:53:50.421: D/cocos2d-x debug info(847): hexagon index 38 //this is the end position 10-28 14:53:57.821: D/cocos2d-x debug info(847): num walkable steps returned by hexagon at index 0 is 1 //not start index! 10-28 14:53:57.821: D/cocos2d-x debug info(847): num walkable steps returned by hexagon at index 9 is 4 10-28 14:53:57.832: D/cocos2d-x debug info(847): num walkable steps returned by hexagon at index 19 is 6 10-28 14:53:57.832: D/cocos2d-x debug info(847): num walkable steps returned by hexagon at index 18 is 3 10-28 14:53:57.832: D/cocos2d-x debug info(847): num walkable steps returned by hexagon at index 10 is 5 10-28 14:53:57.832: D/cocos2d-x debug info(847): num walkable steps returned by hexagon at index 28 is 5 10-28 14:53:57.832: D/cocos2d-x debug info(847): target found!!!!! 10-28 14:53:57.832: D/cocos2d-x debug info(847): step index = 38 10-28 14:53:57.832: D/cocos2d-x debug info(847): step index = 28 10-28 14:53:57.832: D/cocos2d-x debug info(847): step index = 19 10-28 14:53:57.832: D/cocos2d-x debug info(847): step index = 9 10-28 14:53:57.832: D/cocos2d-x debug info(847): step index = 0 10-28 14:53:57.832: D/cocos2d-x debug info(847): step index = -2125467415 10-28 14:53:57.832: A/libc(847): Fatal signal 11 (SIGSEGV) at 0x0a58e044 (code=1), thread 862 (ren.numberboard)

I’m hoping someone might be able to give me a rough idea of the sort of things that can cause the code to run differently. The code compiles and runs perfectly on the iPhone, so I don’t understand how the same code will not work on Android. Eclipse doesn’t seem to be able to give me much data regarding the crash either, so I don’t know where to start.

Here’s the code if anybody has the time to look through, although unfortunately it’s not the shortest function. I’ll be happy with just some general tips on what sort of thing to look for though.

std::vector GameLayer::findPathBetweenPoints(int startIndex, int targetIndex){

    std::list openList;
    std::list closedList;


    pathStep startStep;
    startStep.index = startIndex;
    startStep.fromStartDist = 0;
    startStep.toEndDist = boardDistanceBetweenPoints(startIndex, targetIndex);
    startStep.parent = nullptr;
    startStep.parent = &startStep;

    openList.push_back(&startStep);


    //PATH FINDING LOOP

    do {

    //get lowest scoring from open list

    int lowestScore = 10000;
    pathStep* currentStep;
    int currentStepOpenListIndex;
    int olIndex = 0;

    for (std::list::iterator i = openList.begin(); i!= openList.end(); i++) {
        pathStep *step = *i;
        if (step->score < lowestScore) {
            currentStep = step;
            lowestScore = step->score;
            currentStepOpenListIndex = olIndex;
        }
        olIndex++;
    }
    Hexagon *currentHexagon = _hexagons.at(currentStep->index);

    //check if it is the target
    if (currentStep->index == targetIndex) {
        cocos2d::log("target found!!!!!");
        //return route between points
        std::vector finalRoute;
        pathStep *step = currentStep;
        for (; ; ) {
            cocos2d::log("step index = %d", step->index);

            finalRoute.push_back(step);
            if (step->index == startIndex) {
                return finalRoute;
            }
            step = step->parent;
        }
    }

    //remove the current step from the open list and add it to the closed list
        std::list::iterator iterator = openList.begin();
        std::advance(iterator, currentStepOpenListIndex);
        openList.erase(iterator);

    closedList.push_back(currentStep);

    //get the adjacent nodes
    std::vector walkableSteps = currentHexagon->getWalkableSteps();
    cocos2d::log("num walkable steps returned by hexagon at index %d is %lu", currentHexagon->getIndex(), walkableSteps.size());

    //set the parent to the current node
    for (int i = 0; i < walkableSteps.size(); i++) {
        pathStep *step = walkableSteps.at(i);
        step->parent = currentStep;

    }

    //score the walkable steps and add to open list if not already in either list
    for (int i = 0; i < walkableSteps.size(); i++) {

        pathStep *step = walkableSteps.at(i);
        step->fromStartDist = currentStep->fromStartDist +1;
        step->toEndDist = boardDistanceBetweenPoints(step->index, targetIndex);
        step->score = step->fromStartDist + step->toEndDist;

        bool isInOpenList = false;
        bool isInClosedList = false;

        //check if is in open list
        for (std::list::iterator i = openList.begin(); i!= openList.end(); i++) {
            pathStep *olStep = *i;
            if (olStep->index == step->index) {
                isInOpenList = true;
            }
        }
        //check if is closed list
        for (std::list::iterator i = closedList.begin(); i!= closedList.end(); i++) {
            pathStep *clStep = *i;
            if (clStep->index == step->index) {
                isInClosedList = true;
            }
        }

        //if is not in either list, add to the open list
        if (isInClosedList == false && isInOpenList == false) {
            openList.push_back(step);
        }

    }

    } while (openList.size() != 0);


    cocos2d::log("couldn't find valid path");
    std::vector path;
    return path;
}

According to the touch location and Between the start Point and End point.
CCPoint GamePlayLayer::shortest_distance(cocos2d::CCPoint current_location, cocos2d::CCPoint start_location, cocos2d::CCPoint end_location)
{
float point_x=current_location.x;
float point_y=current_location.y;
float line_x1=start_location.x;
float line_y1=start_location.y;
float line_x2=end_location.x;
float line_y2=end_location.y;
CCPoint sortest_dist;
//find the slope12
float slope_of_line = (line_y1 - line_y2) / (line_x1 - line_x2);
//line is parpendicular equation will be x=a;
if (slope_of_line==INFINITY||slope_of_line==-INFINITY)
{
float x_intercept=line_x1;
float y_intercept=point_y;
sortest_dist=ccp(x_intercept, y_intercept);
// return ccp(x_intercept, y_intercept);
}
//line is horizontal equation will be y=b;
else if(slope_of_line==0||slope_of_line==-0)
{
float x_intercept=point_x;
float y_intercept=line_y1;
sortest_dist=ccp(x_intercept, y_intercept);
//return ccp(x_intercept, y_intercept);
}
else
{
// find the perpendicular slope
float perpendicular_slope = (line_x1 - line_x2) / (line_y1 - line_y2) * -1;
// find the y_intercept of line BC
float y_intercept = (-slope_of_line * line_x2) + line_y2;
// find the y_intercept of line AX
float new_line_y_intercept = -(perpendicular_slope * point_x)+point_y;
//get the x_coordinate of point X
float intersect_x = (y_intercept - new_line_y_intercept) / (perpendicular_slope - slope_of_line);
// get the y_coordinate of point X32
float intersect_y = slope_of_line * intersect_x + y_intercept;
sortest_dist=ccp(intersect_x,intersect_y);
//return ccp(intersect_x,intersect_y);
}
//check if point is between end points…
float total_dist=ccpDistance(CCPoint(line_x1,line_y1),CCPoint(line_x2,line_y2));
float dist_from_a=ccpDistance(CCPoint(sortest_dist.x,sortest_dist.y),CCPoint(line_x1,line_y1));
float dist_from_b=ccpDistance(CCPoint(sortest_dist.x,sortest_dist.y),CCPoint(line_x2,line_y2));
//point is within a segment…
if (total_dist==dist_from_a+dist_from_b)
{
start_pnt=sortest_dist;
return sortest_dist;
}
else
{
//retun object which is nearest to sortest point…
return (dist_from_a>dist_from_b)? CCPoint(line_x2,line_y2):CCPoint(line_x1,line_y1);
}
}