Jump to content
  • Advertisement
Sign in to follow this  
mekanikus

AI problem

This topic is 4187 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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. ^^

Share this post


Link to post
Share on other sites
Advertisement
post the error and the code around the point where the debugger halts execution. Not gonna run your code =)

-me

Share this post


Link to post
Share on other sites
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;


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!