AI problem

Started by
9 comments, last by wodinoneeye 17 years ago
hi, i'm learning pathfinding algorythm. i craete a program with a pathfinding algorythm and my program is buggy, and i think it is serious that windows popup an error message. this is my program along with the source http://files-upload.com/141182/pakuman-shared.zip.html hope someone so kind wants to check it. sry about the link if it couldn't be clicked. thank you. ^^
Advertisement
post the error and the code around the point where the debugger halts execution. Not gonna run your code =)

-me
Good call.

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

thx for your reply.

this is the error code that i get.

"Unhandled Exception in Pakuman.exe:0xC0000005: Access violation"

and it points to this line.

inWhichList[Yposition][Xposition] = IN_CLOSE_LIST;

bellow i add some code above it and bellow it, sry if it's messy

//##############################################################################

Xposition = OpenList[1].x;
Yposition = OpenList[1].y;

inWhichList[Yposition][Xposition] = IN_CLOSE_LIST;

temp = 1;

Node last = OpenList[numberInOpenList--]; //binary heap deletion
int child; //process
for( ; temp * 2 <= numberInOpenList; temp = child)
{
child = temp * 2;

if(child != numberInOpenList && OpenList[child + 1].fCost < OpenList[child].fCost)
child++;

if(OpenList[child].fCost < last.fCost)
OpenList[temp] = OpenList[child];
else
break;
}
OpenList[temp] = last;


Access violation means that you are reading memory where you are not supposed to be. The most common (and almost certainly the cause of this particular crash) is accessing arrays outside of their bounds. That is, accessing element n in an array that has less than n elements.

I would check for any 'off-by-one errors'. Those are extremely common when dealing with arrays. They are could be caused by starting an index to an array at 1, not 0. Also, using <= where you want < or similar mistakes (> instead of >=, ect.) can cause these.

If you need help finding these mistakes, use your debugger. Place a breakpoint. There, and look at what values you are getting. Find out whether this crash happens the first time, or only after some condition. Try putting in an "if(Xposition > sizeOfIndex){ }" in the code right before the crashing line, and have a breakpoint inside of the brackets (make the brackets a separate line). This will let you stop the program and look into it right before the crash happens. You can view the values of many variables at the time of the crash, and see who called this function.

Good luck.
Ezbez is right, use your debugger to find what's happening.

Most likely

Xposition = OpenList[1].x;Yposition = OpenList[1].y;inWhichList[Yposition][Xposition] = IN_CLOSE_LIST;


Xposition or Yposition that's stored in your openlist points to an invalid x/y, probably off by one. If you have an array of 256 elements, the valid range is [0, 255]

Hope this helps

Eric
Thx for your help, i'll try it. ^^

Hi, it's me again.

still couldn't solve the problem. well, Ezbez and xEricx you're right. i've run the program in debug mode, and it showed me that Xposition and Yposition is somewhat a large number, i think much more larger than int value range.

i've been checking the error and it seems that it occurs when i press the movement key (up, down, left, right arrow keys) at some certain tiles.

another question that i want to ask is how to implement the pathfinding algorythm, when should we call it. because i call it at the game loop, it looks like this

gameloop
{
if(timeToDraw)
{
Draw();
findPath();
}
}

i afraid that i call it too many times.

thx.
What is find path supposed to do?

Generally you only need to generate the path once per time the destination changes. If the object is following the path then why generate a new path?

If you find the shortest path, move along the shortest path and the scenary doesn't change, then calculating the shortest path again will yield the same results... So you are just wasting processing time.
The only reason I see why you might want to call FindPath each frame is if you have a path finder manager that receives paths requests and then handles them and notifies the entities when the path is found... otherwise, only call it when the destination changes as shadowisadog said.

You should have separate method to handle path FINDING and path FOLLOWING.

Hope this helps :)

This topic is closed to new replies.

Advertisement