Hi,

I'm experimenting with A Star pathfinding.
I'm having a problem with a function. I'm getting the next error after running it:

Unhandled exception at 0x76ec15de in A Star Pathfinding.exe: 0xC0000005: Access violation reading location 0x08e463a8.

the function's code is:

void addAdjacent(list* oList, list* cList, int tileMap[][40])
{
    node* newParent = oList->nlist[oList->index];
    for(int y=-1; y <= 1; y++)
    {
        for(int x=-1; x <= 1; x++)
        {
            if(y == 0 && x==0){continue;}//skip checking the center node

            node newNode;
            newNode.parent = newParent;
            newNode.setPos(newParent->x + x,newParent->y + y);
            if(validNode(&newNode, tileMap) == true && inList(&newNode, cList) == false)
            {
                oList->addNode(&newNode);
                tileMap[newNode.y][newNode.x] = 4;
            }
        }
    }
    cList->addNode(newParent);//add center node to closed list
    tileMap[newParent->y][newParent->x] = 5;
}

When I tried to debug it seems that the error happened in the last loop.

When I press "continue" after the error, the error seems to happen in tidtable.c in the line

PFLS_GETVALUE_FUNCTION flsGetValue = FLS_GETVALUE;

I don't know what cause this problem. I tried to google for the errors and couldn't find a solution.
Help will be appreciated!

You don't indicate where in your code you are calling into tidtable.c, so we really can't help you much. A couple of observations however. 1. Make sure that all pointer variables are initialized (at least to null) when you declare them. 2. You don't validate the pointers that are passed into your function. If they are null or invalid because they weren't properly initialized, then you are toast.

At line 12 of you code where you create the new node there seems to have been nothing done to check that the value produced is a valid index for the tileMap array.

For example if newParent->x == 0 then on the loop iterations where x == -1 the result will be -1 which if used at lines 16 or 21 or anywhere else tileMap s accessed seems likely to produce an out of bounds access to the tileMap array which would certainly result in the unhandled exception.

Probably the easiest way to catch the error would be to run you program in the symbolic debugger, it should trap the exception and halt allowing you to examine the code and variables at the point of the exception.

I think I found the problem.
I was pointing to newNode, which is a temporary local variable.
Once the "for" loop is over, newNode gets deleted and this what causes the problem.

Could it be the problem?

This question has already been answered. Start a new discussion instead.