A* with Binary Heap error

Started by
9 comments, last by charisma_tubagus 12 years, 1 month ago
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


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;
}
}

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. smile.png
Advertisement
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 ;-)

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

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.astarnullpointererror.png
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?

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

astarerrormemoryviolati.png

That's what I got the error when debugging. Anyway that I can understand this message?
You're accessing a bogus variable, possibly by returning a pointer to a stack-allocated object or something similar.

Check out this article for some tips on reading error messages.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

In particular MSVC uses 0xCCCCCCCC for uninitialized stack variables.
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. mellow.png
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. debugginginassembly2.png
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.

This topic is closed to new replies.

Advertisement