Jump to content
  • Advertisement
Sign in to follow this  
BuraCULa

Heap corruption in std::list

This topic is 2871 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 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); //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
Advertisement
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
i am not spending my time to solve their problem.I try to find the mistake because i am sure one day, also i will face with that problm for my own work.

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!