Sign in to follow this  

A* with Binary Heap error

This topic is 2124 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 have just started learning A* and I did successfully to implement with std::vector in C++. However, when I am integrating my Binary Heap implementation, I have problems with POINTER etc and I have spent much time to debug but still could not get a solution of it. May I ask for a little help?

PROBLEM: Whenever I want to access the parent pointer it will give me run time error. The same algorithm (A*) runs smoothly when I am using std::vector.

Inside my CellNode.h

[CODE]
void Print(){
cout << "Cell Node id : " << m_id << " ("<<m_xcoord << " , " << m_zcoord << ")" <<" F = "<< getF()
<< " G = " << getG() << " H = " << getH();
if ( parent != 0){
cout << "Cell Node Parent id " << parent->m_id << endl;
}
else{
cout << endl;
}
}
[/CODE]
It enters the if condition but it doesn't have any parent reference. I am pretty much confused with this.

In the implementation I am using Visual Studio 2010 and OpenGL as the graphics rendering. Any kind of help is much appreciated..

Thanks. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

Share this post


Link to post
Share on other sites
What's the actual error you get at runtime? The exact text is important.

I suspect you're calling Print() on a null pointer, but that's just an uneducated guess ;-)

Share this post


Link to post
Share on other sites
Hi,

You were right, it does something to do with NULL pointer. Have you tried to create VS 2010 project and copy my source codes? You will see the error looks something like the image attached.[img]http://img9.imageshack.us/img9/1476/astarnullpointererror.png[/img]

Share this post


Link to post
Share on other sites
You should be running this under the debugger (just press F5) and the debugger will give you the actual error that occurs (e.g. Access Violation reading address 0x00000004 or something similar). Can you paste that text here?

Share this post


Link to post
Share on other sites
[img]http://img850.imageshack.us/img850/3345/astarerrormemoryviolati.png[/img]

That's what I got the error when debugging. Anyway that I can understand this message?

Share this post


Link to post
Share on other sites
You're accessing a bogus variable, possibly by returning a pointer to a stack-allocated object or something similar.

Check out [url="http://altdevblogaday.com/2011/09/26/how-did-i-crash-in-that-func/"]this article[/url] for some tips on reading error messages.

Share this post


Link to post
Share on other sites
In particular MSVC uses 0xCCCCCCCC for uninitialized stack variables.

Share this post


Link to post
Share on other sites
Phew...that's a nasty debugging skill I should have. I wil try to revise my Microprocessor Programming concept and theory for this matter. Let me get back to you once I got 'something' from it. Thanks. [img]http://public.gamedev.net//public/style_emoticons/default/mellow.png[/img]

Share this post


Link to post
Share on other sites
Hi,

I am facing a lot of problem when reading assembly language. This is the print screen of debugging with Assembly language. It got an error on this particular line. [img]http://img256.imageshack.us/img256/6742/debugginginassembly2.png[/img]

Share this post


Link to post
Share on other sites
The only pointer dereference that seems to be present is for parent. If parent is a member variable then there may be an implicit dereference of this. So one of the possible situations is that you're calling a member function on an uninitialized pointer to your class. Another situation is that you're calling a member function on a stack object that hasn't initialized the parent member variable for some reason.

Share this post


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