Sign in to follow this  
BuraCULa

Heap corruption in std::list

Recommended Posts

Hi
I have been trying to find the mistake about 1 day.I use <list> library.When i add somedata to list, it works fine couple of times but then it gives me an error:
"windows has triggered a breakpoint. This may be due to a corruption of the heap bla bla" and shows me function __forceinline void * __cdecl _heap_alloc (size_t size).


DUGUM* Solve(DUGUM *start){
std::list<PDUGUM> queue;
std::list<PDUGUM> queue2;

queue.push_front(start);

DUGUM* temp = NULL;

while(! queue.empty()){

temp = queue.back();
queue.pop_back();
if( memcmp(&temp->Case[0][0],&GOAL[0][0],sizeof(int)*9)==0 )break;
queue2.push_back(temp);
FindChildren(temp);

for(int i=0 ; i<temp->childrenCount ;i++){
queue.push_front(&temp->children[i]); //error line
}


}


}

and before the while loop i can add data to list with no error.I belive this line is curved :)

Share this post


Link to post
Share on other sites
I am extremely suspicious about your memcmp() call. How did you decide to compare sizeof(int) * 9 bytes? Can we see the definition of DUGUM and related types?

Your memory ownership semantics are completely unclear. This could be causing your heap corruption troubles. It would be a lot easier if your code was written in C++ rather than C with classes. Using RAII and smart pointers to manage memory.

Share this post


Link to post
Share on other sites
typedef struct DUGUM {
int Case[3][3];
float estimated;
float current;

struct DUGUM * children;
int childrenCount;

struct DUGUM * parent;
}DUGUM,*PDUGUM;

this is the DUGUM struct.I am trying to use a* algorithm to solve 8 puzzle problem.Infact my c++ code works fine with directx and can find the solution but i writed this code for my friends,they dont know classes and c++.This is a homework :)

case[][] member of struct stores the current positions of the tiles.In memcmp call it looks if the current positons of tiles are same with the goal node.

1 2 3
0 5 6
4 7 8(current)

1 2 3
8 0 4
7 6 5(goal)

Share this post


Link to post
Share on other sites
Quote:
Original post by BuraCULa
i writed this code for my friends,they dont know classes and c++.This is a homework :)

So this is you failing to do your friends homework? Maybe they should try it themselves?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this