I am currently working on an AI project. It's about that puzzle you need to move the board pieces numbered from 1 to 8 (and the empty space is labelled as 0) in order to let it sorted at the end. However I got a weird problem when I try to debug it.
int CreateNewState(State *parent, Action action) {
State *newState;
if (!(newState = (State*)malloc(sizeof(State)))) // <<<< Error
return 0;
...
// Populate my newState
newState->parent = parent;
newState->matrix = CreateMatrix();
...
// Insert my newState in the Queue
Insert(newState, myMode);
}
void Insert(State *state, Mode mode) {
State *aux;
if (IsEmpty()) {
myQueue->firstState = state;
myQueue->numberOfElements++;
}
else {
aux = myQueue->firstState;
switch (mode)
{
// Breadth First Search
case BFS:
while (aux->next != NULL) {
aux = aux->next;
}
aux->next = state;
myQueue->numberOfElements++;
break;
...
}
}
}
In the specified Error comment, when I call the CreateNewState() function for the second time, the Debugger stops and popups:
AIProject_Puzzle.exe has triggered a breakpoint.
I tried to bring you guys some additional information in the Call Stack when this error occurs:
ntdll.dll!RtlReportCriticalFailure()
ntdll.dll!RtlpHeapHandleError()
ntdll.dll!RtlpLogHeapFailure()
ntdll.dll!RtlpAllocateHeap()
ntdll.dll!RtlAllocateHeap()
ucrtbased.dll!00007ff9b582c4da()
ucrtbased.dll!00007ff9b582c27d()
ucrtbased.dll!00007ff9b582f34f()
ucrtbased.dll!00007ff9b582fdde()
AIProject_Puzzle.exe!CreateNewState(state * parent=0x000000c05c273520, action action=DOWN)
I know it might be a Heap corruption so, what I really need it is a clue in order to solve this. I am using Visual Studio Community 2015, VisualC++. This error is making me sick. Please could anyone know how to solve this issue?